Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Passing Data from C++ Dll to VB-Application

Passing Data from C++ Dll to VB-Application

Scheduled Pinned Locked Moved C / C++ / MFC
c++testingbeta-testingjsonhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    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

    R 1 Reply Last reply
    0
    • A Anonymous

      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

      R Offline
      R Offline
      Ryan B
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups