Thread View: comp.os.ms-windows.programmer.win32
2 messages
2 total messages
Started by ilardi
Wed, 03 Mar 1999 00:00
Creating DLL's?
Author: ilardi
Date: Wed, 03 Mar 1999 00:00
Date: Wed, 03 Mar 1999 00:00
6 lines
1049 bytes
1049 bytes
Can someone give me an example on how to write a dll in Borland C++ 5 which will return a string to a visual basic program which is calling it? If I define the return value as char will visual basic recognize it as a string? Also, when I try to call it from visual basic I get some kind of error about the function I'm calling not being found within the DLL. What am I doing wrong? Any help would be greatly appreciated!
Re: Creating DLL's?
Author: Eddie Paz
Date: Wed, 03 Mar 1999 00:00
Date: Wed, 03 Mar 1999 00:00
52 lines
2364 bytes
2364 bytes
Here's a BC++ 5 dll that can be used in VB. First Make sure that you choose
"Standard call" in the Project Options | 32-bit Compiler. Note that this is
a C program. If you create a CPP program (MYDLL.CPP), you'll need to add
extern "C" to the beginning of the function
// MYDLL.C
__declspec(dllexport) int SendVBString( char *szString )
{
char *szTmp = "This is the string to be returned";
// Copy the string to the string passed from VB
strcpy( szString, szTmp );
// Put some error checking in here just to be safe
// ...
// return the string length
return strlen( szString );
}
In the General Declarations or module in VB, enter the following:
Private Declare Function SendVBString Lib "mydll.dll" (ByVal vbStr$) As Long
Then to call the function, say when a button is clicked:
Private Sub Command1_Click()
Dim sTmp$, i&
' You have allocate memory for the string. Otherwise the DLL will fail
sTmp$ = Space(255)
i = SendVBString(sTmp)
' Check if a string was returned. If so, display it in a text box
If (i > 0) Then
Text1.Text = Mid(sTmp, 1, i)
End If
End Sub
Hope this helps you.
ilardi wrote in message <36DCA668.197BB617@aol.com>...
>Can someone give me an example on how to write a dll in Borland C++ 5
>which will return a string to a visual basic program which is calling
>it? If I define the return value as char will visual basic recognize it
>as a string? Also, when I try to call it from visual basic I get some
>kind of error about the function I'm calling not being found within the
>DLL. What am I doing wrong? Any help would be greatly appreciated!
>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads