Article View: comp.os.ms-windows.programmer.win32
Article #2126Re: Creating DLL's?
From: 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!
>
Technical Details
Message-ID:
<7biues$fh6$1@oak.prod.itd.earthlink.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<36DCA668.197BB617@aol.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f8d38,ea718bfb93b1af3b X-Google-Attributes: gidf8d38,public X-Google-Thread: 113dfb,ea718bfb93b1af3b X-Google-Attributes: gid113dfb,public From: "Eddie Paz" <epaz@lacera.com> Subject: Re: Creating DLL's? Date: 1999/03/03 Message-ID: <7biues$fh6$1@oak.prod.itd.earthlink.net> X-Deja-AN: 450693712 References: <36DCA668.197BB617@aol.com> X-Posted-Path-Was: not-for-mail X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 X-ELN-Date: 3 Mar 1999 09:13:00 GMT X-ELN-Insert-Date: Wed Mar 3 01:15:18 1999 Organization: EarthLink Network, Inc. Newsgroups: comp.os.ms-windows.programmer.win32,borland.public.cpp.language