本帖最后由 bijiniye1988 于 2009-06-30 14:34:55 编辑

解决方案 »

  1.   

    如果c++是托管的,和c#没有太大区别,
    如果是非托管的 ,建立一个win32 dll 工程
    不过如果你不懂c++,会有不小的麻烦
      

  2.   

    貌似 saucer(思归)  N久都不来了~~~帮你顶吧~~~
      

  3.   

    VC6.0 下:1. 新建 MFC AppWizard 工程, 取名如: SS2. Insert -> New Form 取名如: QQ3. 在 ss.cpp 中引用  #include "qq.h"  并编写 ShowDlg() 函数.
      ss.cpp 中所有代码如下:// ss.cpp : Defines the initialization routines for the DLL.
    //#include "stdafx.h"
    #include "ss.h"
    #include "qq.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endifBEGIN_MESSAGE_MAP(CSsApp, CWinApp)
    //{{AFX_MSG_MAP(CSsApp)
    // NOTE - the ClassWizard will add and remove mapping macros here.
    //    DO NOT EDIT what you see in these blocks of generated code!
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    CSsApp::CSsApp()
    {
    }CSsApp theApp;void ShowDlg( )
    {
    qq qqdlg;AFX_MANAGE_STATE(AfxGetStaticModuleState()); //自动切换当前模块状态
    qqdlg.DoModal();
    return;
    }
    4. 在 ss.def 的 EXPORTS 下导出 ShowDlg 函数, 如:
    EXPORTS
        ; Explicit exports can go here
        ShowDlg5. 完成. 
      

  4.   

    在C#中调用使用:
    [DllImport("Kernel32")]
    public static extern int GetProcAddress(int handle, String funcname);
    [DllImport("Kernel32")]
    public static extern int LoadLibrary(String funcname);
    [DllImport("Kernel32")]
    public static extern int FreeLibrary(int handle); private static Delegate GetAddress(int dllModule, string functionname, Type t)
    {
    int addr = GetProcAddress(dllModule, functionname);
    if (addr == 0)
    return null;
    else
    return Marshal.GetDelegateForFunctionPointer(new IntPtr(addr), t);
    }
    public delegate void ShowDlg(); //委托//调用Dll的代码
    int huser32 = 0;
    huser32 = LoadLibrary("你的动态库.dll");
    ShowDlg show = (ShowDlg)GetAddress(huser32, "ShowDlg", typeof(ShowDlg));
    show(); //调用C++中动态库函数
    FreeLibrary( huser32 );以上代码在VS2005中测试通过。其它DLL相关问题, 参考:
    http://topic.csdn.net/u/20090604/11/7c066445-732e-45f5-a947-b13ce31f1390.html 第1楼的转贴。
      

  5.   

    这要看你的C++程序是用什么开发的,用的哪种项目模板。例如用VS.NET开发的基于对话框的MFC程序,可以在项目属性中将配置类型改为动态库,将App类InitInstance函数中创建对话框的相关代码删除,例如增加一个导出函数来创建和显示对话框。C#中用DllImport声明extern函数。
      

  6.   

    这种事何必麻烦大虾。
    很简单,四种方法都可以,但首先你必须生成这个dll。
    第一种,前期绑定
    第二种,后期绑定
    第三种,Com呃。。是COM还是Active?反正会做但不知道叫什么
    第四种,这也是最强大的一种。用C#再写一个- -!!!
      

  7.   

    把具体的C++项目说说吧还有你在转为DLL  在C#中不能正确执行时遇到的具体问题 说说吧
      

  8.   


    我目前没有碰到在C#如法正常调用的情况,因为dll还没有生成出来