LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing Strings from Lab Windows/CVI dll function to VBA Macro

Solved!
Go to solution
I would like to pass a string from a Lab Windows/CVI dll to a VBA macro.  I have been successful passing strings from VBA to Lab Windows but can't seem to get the string to go the other way.  I have been searching far and wide for this answer.  It seems like it shouldn't be that difficult but I guess I’m missing something.  I would like to know what the dll prototype should look like and how to manipulate the string value inside the dll code.  The following code snippets are what I’m currently trying but I have also tried several variations of this including passing the string ByVal instead of ByReference and different casting from within the DLL but I just can’t get this to work.  The Lab Windows DLL Function looks like this: void DLLEXPORT PassBackAString (char *strTextBuffer){    strcpy (*strTextBuffer, "You did it");}  And the VBA declaration and call looks like this: Declare Sub PassBackAString Lib "My.dll" (strTextBuffer As String) Dim strTextBuffer As String strTextBuffer = String$(1024, vbNullChar)Call PassBackAString (strTextBuffer)

 

0 Kudos
Message 1 of 2
(3,677 Views)
Solution
Accepted by topic author Rick1458

To interface to VBA code, you need to use the stdcall qualifier on the CVI function definition. There may also be a small typo in your posting - try changing your code from:

 

    void DLLEXPORT PassBackAString (char *strTextBuffer) {strcpy (*strTextBuffer, "You did it");} 

 

to:

 

    void DLLEXPORT DLLSTDCALL PassBackAString (char *strTextBuffer) {strcpy (strTextBuffer, "You did it");} 

 

JR

0 Kudos
Message 2 of 2
(3,649 Views)