Results 1 to 5 of 5

Thread: Visual C++ DLL won't work with VB

  1. #1

    Thread Starter
    Member
    Join Date
    May 2002
    Location
    Great Britain
    Posts
    60

    Visual C++ DLL won't work with VB

    Didn't know where to post this as it's both VB and VC code, heres goes:

    I have a DLL which contains this function:

    void _stdcall cryptArray(unsigned char *bArray, long bArrayLen)
    {
    for (long i=0; i<=bArrayLen; ++i)
    {
    bArray[i]=bArray[i]^5;
    }
    }

    To use this is Visual Basic, I call it with a procedure similar to this:

    Public Declare Sub cryptArray Lib "C:\My Documents\Visual C++\XorEnc DLL\Debug\XorEnc DLL.dll" (Bytes As Byte, NumBytes As Long)

    Dim Bytes(0 To 3) As Byte
    For t = 0 To 3
    Bytes(t) = t
    Next
    cryptArray Bytes(0), 4

    When I do this I get a "Vb6 has caused an error..." in the above DLL.
    Can anyone see where I've gone wrong?

  2. #2
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    strings need to BSTR, not char *

    also.
    Code:
    extern "C" {
    void _stdcall cryptArray(BSTR bArray[], long bArrayLen)
    {
    for (long i=0; i<=bArrayLen; ++i)
    {
    (LPCSTR)bArray[i]=(LPCSTR)bArray[i]^5;
    }
    }
    }
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  3. #3

    Thread Starter
    Member
    Join Date
    May 2002
    Location
    Great Britain
    Posts
    60
    I still get the same error. I'm not sure if the cause is in the visual basic part (particularly the Public Declare), or whether it's the C code.
    Can anyone else help?

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Visual C++ DLL won't work with VB

    Originally posted by CactusCat
    Didn't know where to post this as it's both VB and VC code, heres goes:

    I have a DLL which contains this function:

    void _stdcall cryptArray(unsigned char *bArray, long bArrayLen)
    {
    for (long i=0; i<bArrayLen; ++i)
    {
    bArray[i]=bArray[i]^5;
    }
    }

    To use this is Visual Basic, I call it with a procedure similar to this:

    Public Declare Sub cryptArray Lib "C:\My Documents\Visual C++\XorEnc DLL\Debug\XorEnc DLL.dll" (ByVal Bytes As Long, ByVal NumBytes As Long)

    Dim Bytes(0 To 3) As Byte
    For t = 0 To 3
    Bytes(t) = t
    Next
    cryptArray VarPtr(Bytes(0)), 4

    When I do this I get a "Vb6 has caused an error..." in the above DLL.
    Can anyone see where I've gone wrong?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Member
    Join Date
    May 2002
    Location
    Great Britain
    Posts
    60
    THANK YOU! I'd forgotten about the VarPtr function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width