DLL question -- integrating VB with C++ DLL 
Author Message
 DLL question -- integrating VB with C++ DLL

This looks like a good place to ask this type of question...

I'm having some weird problems trying to get a VB program to use a C DLL.

My VB program which calls the DLL is abending strangely, will errors like
the following:

"The instruction at "0x77f34cab" referenced memory at "0x001d7000".  The
memory could not be read."

"Out of memory (Error 7)".

It is difficult to reproduce the problems every time.  Sometimes they occur
immediately (after the first button click), sometimes they happen after
three clicks (each click invokes the DLL).

The DLL is basically a sockets interface written in C which talks to the
rest of my application.  The VB part just calls the DLL and returns the
results.  The program always blows up when calling erremotecmd (see below).
Trace code put into the DLL also indicates that everything processed
successfully and that a return code of 0 was passed back to the caller.

The DLL does no dynamic memory allocation on its own.  I'm wondering if VB
does.  The only other thing I could think of was that my DLL was overwriting
the memory of VB (the DLL does copy data into a string buffer provided by
VB).  However, I don't think that is the case either, since I've statically
allocated string space in the VB program far in excess of what is needed
(and I've varied that amount to see if I had done too much).

One other thing I tried was writing the same code in C, and calling the DLL
from C.  This works as expected, in other words, no problems at all.

C prototypes for DLL calls:

void __stdcall erremotecmdsetoption (int option_id, int option_val);

int __stdcall erremotecmd (char *host, char *mgrport, char *request,
                           char *reply, int *replycnt, char *errmsg);

VB Code:

Private Declare Function erremotecmd Lib
"\eric\projects\dllcall\debug\ggscidll.dll" (ByVal host As String, ByVal
port As String, ByVal request As String, ByVal reply As String, ByRef
replycnt As Long, errmsg As String) As Long
Private Declare Sub erremotecmdsetoption Lib
"\eric\projects\dllcall\debug\ggscidll.dll" (ByVal option_id As Long, ByVal
option_val As Long)

Private Sub Command2_Click()
    Dim res As Long
    Dim request As String * 500
    Dim reply As String * 5000
    Dim errmsg As String * 500
    Dim replycnt As Long

    'turn tracing on
    'Call erremotecmdsetoption(2, 1)
    Call erremotecmdsetoption(1, 1)

    'request = String(500, 0)
    'reply = String(5000, 0)
    'errmsg = String(500, 0)

    'request = command.Text

    res = erremotecmd(host.Text, port.Text, command.Text, reply, replycnt,
errmsg)

    results.Text = reply
    errortext.Text = errmsg

    results2.SelStart = 0
    results2.SelLength = replycnt
    results2.SelFontName = "Courier"
    results2.SelFontSize = 10

    results2.TextRTF = Left(reply, replycnt)
End Sub



Tue, 05 Nov 2002 03:00:00 GMT  
 DLL question -- integrating VB with C++ DLL


Quote:
> This looks like a good place to ask this type of question...

Nope. We're kernel mode programmers. We write device
drivers. Fortunately, we don't have to write device
drivers in Visual Basic.


Tue, 05 Nov 2002 03:00:00 GMT  
 DLL question -- integrating VB with C++ DLL

 ..., ByVal errmsg as string)...    did you miss this one?

Quote:

> This looks like a good place to ask this type of question...

> I'm having some weird problems trying to get a VB program to use a C DLL.
> ...

> int __stdcall erremotecmd (char *host, char *mgrport, char *request,
>                            char *reply, int *replycnt, char *errmsg);

> VB Code:

> Private Declare Function erremotecmd Lib
> "\eric\projects\dllcall\debug\ggscidll.dll" (ByVal host As String, ByVal
> port As String, ByVal request As String, ByVal reply As String, ByRef
> replycnt As Long, errmsg As String) As Long
>                   ^^^^^^

--
Posted via CNET Help.com
http://www.help.com/


Fri, 08 Nov 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. I need testers for serial port comm DLL and alpha paging DLL (Delphi, C/C++, VB)

2. VB DLL reading from ADO and colliding with C++ DLL reading there too (on NT)

3. VB 5.0 calling C++ 5.0 DLL that calls winsock.dll

4. Question regarding BSTR Visual c++ dll and VB 6- Please help

5. Compiling a C++ code to build a .DLL using VB Calls Question

6. accessing objects in a c++ DLL from a c++ activeX control placed in a VB application

7. DLL DLL DLL DLL DLL DLL

8. VB ActiveX dll integrated with MS Project 98

9. integrating dll's with a vb application ????

10. C++ DLLs vs C DLLs

11. SPEED: VB5 ActiveX DLL vs C++ ATL COM DLL

12. call another DLL from within a C++ DLL

 

 
Powered by phpBB® Forum Software