如题 谢谢、

解决方案 »

  1.   

    可以 
    看了这个例子,你应该会了,这样声明一下就可以用了 
    [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)] 
    public static extern IntPtr GetWindowDC(IntPtr hwnd);以前别人回复的,我转
      

  2.   

    可以 C#编写的Assmebly要设置 ComVisible = true这里是具体的http://support.microsoft.com/kb/828736
      

  3.   

    楼上的是C# call C++ dllhttp://www.daniweb.com/forums/thread90053.html
      

  4.   

    调用C#的DLL 应该和调用普通的COM接口完全一样 主要是Assmebly要写成COM可见的
    // CPPClient.cpp: Defines the entry point for the console application.
    // C++ client that calls a managed DLL.#include "stdafx.h"
    #include "tchar.h"
    // Import the type library.#import "..\ManagedDLL\bin\Debug\ManagedDLL.tlb" raw_interfaces_only
    using namespace ManagedDLL;
    int _tmain(int argc, _TCHAR* argv[])
    {
        // Initialize COM.
        HRESULT hr = CoInitialize(NULL);    // Create the interface pointer.
        ICalculatorPtr pICalc(__uuidof(ManagedClass));    long lResult = 0;    // Call the Add method.
        pICalc->Add(5, 10, &lResult);    wprintf(L"The result is %d\n", lResult);
        // Uninitialize COM.
        CoUninitialize();
        return 0;
    }
      

  5.   

    我按照VS帮助,创建的是一个动态库dll,如何生成类型库呢?(tlb)
      

  6.   

    每次执行到这里 都报错 ICalculatorPtr pICalc(__uuidof(ManagedClass));
      

  7.   

    刚试了试 C++/CLI,库:// cl /clr clrdll.cpp /LD user32.lib
    #include <windows.h>
    #include <tchar.h>
    #using <System.dll>
    #using <System.Windows.Forms.dll>int __declspec(dllexport) f1(LPTSTR msg)
    {
      System::Windows::Forms::MessageBox::Show("hello from dll");
      ::MessageBox(::GetDesktopWindow(), msg, TEXT("info"), MB_OK);
      return 0;
    }
    测试的客户端, 控制台程序:// cl /clr testclrdll.cpp clrdll.lib 
    #include <windows.h>
    #include <tchar.h>int f1(LPTSTR msg);int main()
    {
      f1("消息");
      return 0;
    }