我有一个vc6.0写的dll想在c#里用。里面有一个定义回调函数,
typedef void  (__stdcall *DATARCVCALLBACK )( UINT16 usMessageType,  INT8 *pBuffer, UINT32 uiLengthOfData, ICSH stConnectionHandle );该定义在函数---  CRO WINAPI __stdcall ConnectToIAMSServer( ICSH *pSessionHandle, 
  UINT32 uiTimeOutValue, 
  DATARCVCALLBACK pDataRcvCallback,
  HWND frmmain_hwnd,
  unsigned int WindowMsg); 
被用,我现在想在c#里用ConnectToIAMSServer,该怎么写。谢谢。

解决方案 »

  1.   

    public delegate void PDTDataReceivedCallBack(UInt16 usMessageType,
                                        string pBuffer,
                                        UInt32 uiLengthOfData,
                                        UInt32 stConnectionHandle);
            public static void PDTDataReceived(UInt16 usMessageType,
                                       string pBuffer,
                                       UInt32 uiLengthOfData,
                                       UInt32 stConnectionHandle)
            {            
            }[DllImport("..\\dll.dll")]
             public static extern int ConnectToIAMSServer(IntPtr pSessionHandle, Int32 uiTimeOutValue,
                                    PDTDataReceivedCallBack pDataRcvCallback, IntPtr frmmain_hwnd,
                              UInt32 WindowMsg);姑且这样编译过去了,不过还是连不上。
      

  2.   

    最好先用dumpbin命令行,先确认一下dll里面是否正确输出了导出函数。另外,如果导出时没用用extern C的话,导出的函数名会有一些奇怪的符号,你在C#中定义入口的时候要加上这些符号。
    [DllImport(@"C:Bin\\DC.dll",
    EntryPoint = "?DisPagePDF@@YAHPB_WH00_NHH@Z",
    CallingConvention = CallingConvention.Cdecl)]
            public static extern Int32 DisCorrOnePageInPDF(
                string src, int index, string oriImagePath, string dest, bool edge, int papersetting, int directsetting);
      

  3.   

     00000000 characteristics
        3B5B44D6 time date stamp Sun Jul 22 14:25:42 2001
            0.00 version
               1 ordinal base
              26 number of functions
              26 number of names    ordinal hint RVA      name          1    0 00003DC0 AddRTSMessageToRequestBundle
              2    1 00004740 AddUDSMessageToBundle
              3    2 00003B40 BuildRTSCommandRequestMessage
              4    3 00003CA0 BuildRTSMessageRequestMessage
              5    4 00003C00 BuildRTSResponseRequestMessage
              6    5 00004670 BuildUDSMessageRequest
              7    6 00001BD0 ConnectToIAMSServer
              8    7 00002110 DisconnectFromIAMSServer
              9    8 00003850 IAMSHouseKeepingProcess
             10    9 00001760 InitializeIAMSClient
             11    A 00004080 ParseRTSIndication
             12    B 00002580 PollForNewDataFromIAMSServer
             13    C 000026B0 ProcessIncomingMessage
             14    D 000022A0 SendMessageToIAMSServer
             15    E 000024B0 SendUserBuiltMessageToIAMSServer
             16    F 00001AE0 SetDataReadTimeOut
             17   10 00001A50 SetDataWriteTimeout
             18   11 00001A80 SetHeartBeatInterval
             19   12 00001B30 SetIAMSClientAPIBlocking
             20   13 00001B10 SetIAMSClientAPINonBlocking
             21   14 00002600 SetIAMSServerName
             22   15 00001910 SetPassword
             23   16 000019D0 SetSSHostName
             24   17 00001970 SetSSX121AddressName
             25   18 00002680 SetServerPort
             26   19 00002690 SetTraceLevel下面是用dumpbin的结果。看起来名字都挺正常的。