以前的一个C#做的exe程序,里面的一些功能要复用到现在一个vc做的程序里面,那位大牛知道这个应该怎么修改?
怎么开接口,怎么调用?
怎么开接口,怎么调用?
解决方案 »
- 求解答:IDispatch接口该如何设置回调
- MFC 分屏后想其中一个窗口中添加List的问题
- OpenGL拾取问题
- 用什么把DLL反编译回来?
- 如何改变打开文件对话框的样式?
- 如何把字符串转换为int类型?
- ActiveX + CAsyncSocket = ?? 搞不懂吖
- 怎么回这样的????????????????????????????????????(在线!!!)
- SOCKET问题在线等候
- 关于解密的问题:谁可以帮助我解掉计算机等级考试模拟盘的密,希望提供解密软件,发到我的信箱里! [email protected] 不胜感谢!
- socket接收文本时缓冲区写错误怎么办??
- 求字符识别的原理和程序c语言
要是MFC那就只能按照c#编的那些功能重写了
Enable function-level control for compiling functions as managed or unmanaged.
#pragma managed
#pragma unmanaged
#pragma managed([push,] on | off)
#pragma managed(pop)
Res
The /clr compiler option provides module-level control for compiling functions either as managed or unmanaged.An unmanaged function will be compiled for the native platform, and execution of that portion of the program will be passed to the native platform by the common language runtime.Functions are compiled as managed by default when /clr is used.Use the following guidelines when applying these pragmas:Add the pragma preceding a function but not within a function body.Add the pragma after #include statements (do not use these pragmas before #include statements).The compiler ignores the managed and unmanaged pragmas if /clr is not used in the compilation.When a template function is instantiated, the pragma state at the time of definition for the template determines if it is managed or unmanaged.For more information, see Initialization of Mixed Assemblies.Example
Copy Code
// pragma_directives_managed_unmanaged.cpp
// compile with: /clr
#include <stdio.h>// func1 is managed
void func1() {
System::Console::WriteLine("In managed function.");
}// #pragma unmanaged
// push managed state on to stack and set unmanaged state
#pragma managed(push, off)// func2 is unmanaged
void func2() {
printf("In unmanaged function.\n");
}// #pragma managed
#pragma managed(pop)// main is managed
int main() {
func1();
func2();
}
Copy Code
In managed function.
In unmanaged function.
我看了看反汇编, 托管的被编译成中间语言, 非托管的是传统汇编码.
很奇特的一种组合....还能被Reflector反汇编....真够好玩的.....
一是改用C++/CLI,直接引用C#程序集.
二就比较麻烦,可能需要你重新编译C#程序.
首先C#程序必须是强签名的;然后你希望重用的类必须是公开的.
接着用gacutil把这个C#程序安装到GAC;最后用regasm注册这个
程序集.现在你就可以在VC里调用CoCreateInstance创建C#程序里的托管类实例了.
在COM它被公开为一个IDispatch.你也可以自己声明一个类接口直接转型过来用.
可以先把C#写成DLL, 然后调用.
网上非托管C++调用C#的资料挺多的你看看.想在代码级复用, 如果代码不多的话, 可以改写成托管C++代码啊, 反正语法差不多, 你认为呢?