LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

calling c function that return a string

Hallo,

 

I found an example for calling void c function(http://zone.ni.com/devzone/cda/epd/p/id/1513). I could adapt the example and make the function return an integer. the code of the adapted function would look like this:

 

int
__declspec(dllexport) multiply(int number)

{

return number*3;

}

 

But I have problems when I want to return a string. Does someone knows how I should do. I tried:

 

char* __declspec(dllexport) say(int number)

{

return "hallo";

 

but won't compile.

 

0 Kudos
Message 1 of 4
(2,881 Views)

I haven't worked with C-connections or dll's much, but technically you're not returning a string, but a character pointer. As such you get the adress where the string starts as an integer. You'll need to typecast the int-adress to a string.

Check your code when running and i'm sure the C-call returns a 32-bit int alot bigger than a normal character.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 4
(2,867 Views)

davico wrote:
but won't compile.

Are you asking a C question, or a LabVIEW question?  What's the error message?

0 Kudos
Message 3 of 4
(2,860 Views)

yes the question was  more a c question then a labview question. I found the solution anyway, the correct code in order to get string is:

 

_declspec(dllexport) char* testchar2();

_declspec(dllexport) char* testchar2()

{

      return "hallo";

}

0 Kudos
Message 4 of 4
(2,854 Views)