以前的一个C#做的exe程序,里面的一些功能要复用到现在一个vc做的程序里面,那位大牛知道这个应该怎么修改?
怎么开接口,怎么调用?

解决方案 »

  1.   

    要是vc.net托管的,代码可以拷过来,可以改改
    要是MFC那就只能按照c#编的那些功能重写了
      

  2.   

    C#是托管的,不能移植到vc里,否则大家都用C#写了,C#多容易啊
      

  3.   

    C#调VC到可以,Vc的做成dll就行了;反过来困难
      

  4.   

    要看了。移植到VC.Net托管下很简单,非托管就得费心的改代码了
      

  5.   

    谢谢 楼上几位的回复, vc的代码不是vc.net托管的,那个C#程序里面还涉及到很多界面,所以照着改就不太可能了,一些控件什么和mfc都不太一样的,因为vc里面可以做成dll给其他的调用,所以在想有没有类似的方法把那个C#改了给VC调用?
      

  6.   

    使用/clr编译选项, 和#pragma managed/#pragma unmanaged
    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反汇编....真够好玩的.....
      

  7.   

    两种办法...
    一是改用C++/CLI,直接引用C#程序集.
    二就比较麻烦,可能需要你重新编译C#程序.
    首先C#程序必须是强签名的;然后你希望重用的类必须是公开的.
    接着用gacutil把这个C#程序安装到GAC;最后用regasm注册这个
    程序集.现在你就可以在VC里调用CoCreateInstance创建C#程序里的托管类实例了.
    在COM它被公开为一个IDispatch.你也可以自己声明一个类接口直接转型过来用.
      

  8.   


    可以先把C#写成DLL, 然后调用.
    网上非托管C++调用C#的资料挺多的你看看.想在代码级复用, 如果代码不多的话, 可以改写成托管C++代码啊, 反正语法差不多, 你认为呢?