void __stdcall FillString(LPSTR pszString, LONG cSize) { // Create a temp buffer with our string char buffer[] = "Hello from the C DLL!"; // Copy our temp string to pszString // but check the size to make sure we have a buffer // big enough to hold the entire string. if (cSize > strlen(buffer)) strcpy(pszString, buffer); } To make the functions exportable, add the following to "StrSamp.def:" LIBRARY StrSamp DESCRIPTION 'Microsoft KB Sample DLL' EXPORTS FillString VB declare: Private Declare Sub FillString Lib "StrSamp.dll" _ (ByVal sMyString As String, ByVal cBufferSize As Long)sample Dim sFillTest As String sFillTest = Space$(260) FillString sFillTest, 260 MsgBox Trim$(sFillTest), vbInformation, "Fill String"
{
// Create a temp buffer with our string
char buffer[] = "Hello from the C DLL!"; // Copy our temp string to pszString
// but check the size to make sure we have a buffer
// big enough to hold the entire string.
if (cSize > strlen(buffer))
strcpy(pszString, buffer);
}
To make the functions exportable, add the following to "StrSamp.def:" LIBRARY StrSamp
DESCRIPTION 'Microsoft KB Sample DLL'
EXPORTS
FillString
VB declare:
Private Declare Sub FillString Lib "StrSamp.dll" _
(ByVal sMyString As String, ByVal cBufferSize As Long)sample
Dim sFillTest As String sFillTest = Space$(260)
FillString sFillTest, 260
MsgBox Trim$(sFillTest), vbInformation, "Fill String"