c.dll
c.c code
__declspec(dllexport)  
void boxid_translate_mac_to_boxid(const char* mac_addr, char* boxid_str)+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
VB activeX Dll modCdll.bas  codeOption ExplicitPublic Declare Sub boxid_translate_mac_to_boxid Lib "c.dll" (ByVal MAC$, ByVal BoxID$)clsBoxID.clsOption ExplicitPublic MAC As StringPublic Function Get_BoxID() As String
    Dim BoxID     As String
    'mac = String(256, 0)
    BoxID = String(256, 0)
    boxid_translate_mac_to_boxid MAC, BoxID
    Get_BoxID = BoxID
End Function
          
Public Property Let vMAC(ByVal num As String)
    MAC = num
End Property
             
Private Sub Class_Initialize()
    MAC = String(256, 0)
End Sub+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
封装后生成新的DLL(BoxID.dll),并且regsvr32注册成功VB standed EXEform窗体上两个textbox(txtMAC,txtBoxID), 两个commandbutton(btnCal,btnEXIT)Private Sub btnCal_Click()    Dim getBoxID As New BoxID.clsBoxID
    
    getBoxID.vMAC = CStr(Trim(txtMAC.Text))
    
    'txtBoxID.Text = getBoxID.strTest(mac)
    
    txtBoxID.Text = getBoxID.Get_BoxID
    
End SubPrivate Sub btnExit_Click()
    End
End SubPrivate Sub Form_Load()
    btnCal.Enabled = False
End SubPrivate Sub txtMAC_Change()
    If Len(txtMAC.Text) = 12 Then
        btnCal.Enabled = True
        txtBoxID.Text = ""
    Else
        btnCal.Enabled = False
        txtBoxID.Text = ""
    End If
End Sub测试数据
in : 004063E3291C
out: BUMAPMV9H9CSP我在vb上直接调试是通过的,但是生成的EXE却不能工作其实我最终的目的是ASP调用,我用ASP也进行了测试,但是报错,下面是
get_BoxID.asp code
  
        
      <html>     
      <head><title>Reference DLL</title></head>     
      <body>     
        <%     
   
      Set BoxID=Server.Createobject("BoxID.clsBoxID")     
       
      %> 
  <form action="get_BoxID.asp" method="post">
  <input type="text" name="mac" maxlength="12">
  <input type="Submit" value="Submit">
  <input type="hidden" value="1" name="hh">
  </form>
  <%
   if request.Form("mac")<> "" then
dim mac
mac = (request.Form("mac"))
if request.Form("hh")=1 then
'response.write BoxID.strTest(mac)
BoxID.vMAC = mac
response.write BoxID.Get_BoxID
end if
else
response.write "please input a valid MAC."
end if
  %>      </body>     
  </html>
错误类型:
Response 对象, ASP 0106 (0x80020005)
遇到未处理的数据类型。
/boxid/get_BoxID.asp谢谢

解决方案 »

  1.   

    如果那位有时间帮忙我的话,可以到我的邮件里得到source code 调试
    非常的感谢
    User: [email protected]
    PWD : chelsea请不要随意修改我的密码
      

  2.   

    在Set BoxID=Server.Createobject("BoxID.clsBoxID")  下面
    直接str=BoxID.Get_BoxID
     response.write str试试
      

  3.   

    在Set BoxID=Server.Createobject("BoxID.clsBoxID")     
    加str=BoxID.Get_BoxID
    response.write str
    试试
      

  4.   

    谢谢
    CathySun118(斯年) 我的DLL写的有问题,单步调的时候,
    c
    __declspec(dllexport)  
    void boxid_translate_mac_to_boxid(const char* mac_addr, char* boxid_str)vb
    Public Declare Sub boxid_translate_mac_to_boxid Lib "c.dll" (ByVal MAC$, ByVal BoxID$)Private Sub Class_Initialize()
        MAC = String(256, 0)
    End Sub
    初始化就出问题了试了很多方法,都不能解决,就是调用C指针的问题
      

  5.   

    BoxID.Get_BoxID返还的是什么类型?
      

  6.   

    BoxID.Get_BoxID返还的是什么类型?返回string好像不关这些吧就是引用指针出错,我也不晓得怎么弄了
      

  7.   

    Public Declare Sub boxid_translate_mac_to_boxid Lib "c.dll" (ByVal MAC() as Byte, ByVal BoxID() as Byte)在调用前要给字节数组初始化指定大小,这个大小不能小于DLL所需要的大小(别忘记字符串结尾还有个\0)
      

  8.   

    char* 对应到VB应该是 byte()数组类型传递时最好传递一个uboundV来确保数组不溢出.