Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
This Document is not yet Rated  Rate this Document

Passing a String from Visual Basic 6 to an ANSI C DLL

Primary Software: Measurement Studio>>Visual Basic Support
Primary Software Version: 1.0
Primary Software Fixed Version: N/A
Secondary Software: Measurement Studio>>Visual C++ Support

Problem:
Why do I get garbled ASCII characters when I try to pass a string from a Visual Basic 6 (VB 6) function to an ANSI C DLL.

Solution:
Visual Basic 6 (VB 6) and ANSI C store strings differently so you cannot pass a string by reference from VB 6 and to an ANSI C DLL as you would if you were to pass that string to a VB 6 function.

For example:

The function being called in the ANSI C DLL is declared as this:

    int32 __stdcall ReadString(const char tempString[])


The prototype for the function call in VB 6 needs to be declared and the string passed by value instead of reference:
   
    Declare Function ReadString(ByVal physicalChannel As String) as Long


Then you call the function in VB 6 with a string

    CreateAIVoltageChan("Hello World")


Related Links:

Attachments:





Report Date: 01/14/2008
Last Updated: 02/19/2008
Document ID: 4HDGQ69S

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit