我在VC中做了个MFC 静态DLL,函数定义如下:
extern "c" _declspec(dllexport) bool TestPort(UINT portnr,UNIT baud)现在在VC中调用正确,但在VB中调用出错,请高手指点,我想这个DLL在另外的语言中都能调用正确。

解决方案 »

  1.   

    使用如下定义
    bool __stdcall TestPort(UINT portnr,UNIT baud)
    在.def文件中
     TestPortTry again
      

  2.   

    前面不用加extern "C"吗?
    我试过exitern "C" __stdcall bool TestPort
    但调用还是有问题,不会出错,但调用不成功,也就是DLL就像没运行一样。注:VC 下写的DLL主要功能是通过串口像单片机发送验证密码,然后获得密码进行计算再返回结果(真或假),其中采用了多线程。大家帮我分析下原因,谢谢!!!!!!!!
      

  3.   

    不用加,
    bool __stdcall TestPort(UINT portnr,UNIT baud)
    BOOL 放在前面
      

  4.   

    楼上的谢了,用你的方法我实验成功了!
    但是现在还有个问题,我在DLL里设置的函数返回的是BOOL,在VC里能正确返回TRUE或者FALSE,但 在VB里调用却一直返回FALSE,我在VB里是这样调用的:
    Private Declare Function TestPort Lib "D:\ResourcesFile\VC\串口通信\ComDll\Release\ComDll.dll" (ByVal portnr As Integer, ByVal baud As Integer) As BooleanPrivate Sub Command1_Click()
     dim Tes as boolean
     Tes=TestPort(1,9600) 
     If Tes=true Then
        Text1.Text = "返回正确……"
     Else
        Text1.Text = "返回不正确……"
     End If
    End Sub
      

  5.   

    错了,刚才我语句写错了,应该是:
    if Tes Then
       ……
    else
       ……
    end if但是我调试了Tes=TestPort(1,9600)这句它一直都是返回真。
      

  6.   

    哈哈!小弟终于问题解决,我把VC DLL中的函数返回类型改为UINT,即:
    UINT __stdcall TestPort(uint portnr,uint baud)
    如果测试成功返回return (1);否则return (0)。
    在VB中声明
    Private Declare Function TestPort Lib "D:\ResourcesFile\VC\串口通信\ComDll\Release\ComDll.dll" (ByVal portnr As Integer, ByVal baud As Integer) As Boolean
    这样就可在VB中调用成功。可是……
    问:函数我声明的UINT,怎么在VB中能生命boolean,如果不这样,我应该声明什么类型?