Passing Data from C++ Dll to VB-Application
-
hi there, i have a problem to pass a String (a very large one) from a Visual C++ Dll to a VB-Application. The problem is that only the first 1024 letters reaching the VB-App - so where is rest? I am not very skilled in vb-programming so: is there a limited size of a string in VB? What do you think is the problem? Here is an example of the dll an vb - code: //VC++ DLL ------------------------------------------------------------------- BSTR __stdcall RunDll2 (LPCSTR str ) { CString s(str); AfxMessageBox( s, MB_OK, 0); //only for testing reasons: CFile file; CString strs; if ( file.Open( "listerror.rtf", CFile::modeRead ) ) { int size = file.GetLength(); char * cbuffer = new char[size-4]; file.Read(cbuffer, size); strs = cbuffer; file.Close(); } s = strs; //---------------------------------- LPSTR str1= new char[s.GetLength()]; strcpy(str1, s); BSTR bstr = SysAllocString((OLECHAR*)str1); return bstr; } ------------------------------------------------------------------- VB Code------------------------------------------------------------------- Option Explicit Private Declare Function myfunction Lib "DllTest.dll" Alias "RunDll2" (ByVal mystring As String) As String Private Sub Main() Dim mystring As String Dim mystring2 As String Dim out As String mystring = "jkljökjklöjlksadfdasfdasf afkjsdölkfdf" out = mystring mystring2 = myfunction(mystring) MsgBox mystring2 End Sub
-
hi there, i have a problem to pass a String (a very large one) from a Visual C++ Dll to a VB-Application. The problem is that only the first 1024 letters reaching the VB-App - so where is rest? I am not very skilled in vb-programming so: is there a limited size of a string in VB? What do you think is the problem? Here is an example of the dll an vb - code: //VC++ DLL ------------------------------------------------------------------- BSTR __stdcall RunDll2 (LPCSTR str ) { CString s(str); AfxMessageBox( s, MB_OK, 0); //only for testing reasons: CFile file; CString strs; if ( file.Open( "listerror.rtf", CFile::modeRead ) ) { int size = file.GetLength(); char * cbuffer = new char[size-4]; file.Read(cbuffer, size); strs = cbuffer; file.Close(); } s = strs; //---------------------------------- LPSTR str1= new char[s.GetLength()]; strcpy(str1, s); BSTR bstr = SysAllocString((OLECHAR*)str1); return bstr; } ------------------------------------------------------------------- VB Code------------------------------------------------------------------- Option Explicit Private Declare Function myfunction Lib "DllTest.dll" Alias "RunDll2" (ByVal mystring As String) As String Private Sub Main() Dim mystring As String Dim mystring2 As String Dim out As String mystring = "jkljökjklöjlksadfdasfdasf afkjsdölkfdf" out = mystring mystring2 = myfunction(mystring) MsgBox mystring2 End Sub
You might want to try passing in a reference to a string instead of returning one from C++. I had to populate a shared data structure (UDT) between VB and C, however, one of the members of the UDT was a String. I passed a reference to an array of UDT's to my C DLL, and used SysAllocString on the String member. The data passed fine. All in All i was returning about 40K of data in the one function call. I dont have any useful code for you though. Question: Are you using IDL? Ryan Baillargeon Software Specialist Fuel Cell Technologies Inc.