LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

getting "Call library function node' to work

I am trying to get the Call library function node to work.
I do not have any experience with Labview and DLLs, but there is a
tedious task I would like to automate.

I want to use a function from a dll with the following definition:

function oziLoadMap(var MapName:pansichar):integer;stdcall;

It is from the oziexplorer API (software for navigation and reading
maps).

Whatever I try I allways get: "an exception occurd within the external
code..."

My guess would be to use the STDCALL calling convention.
A unsigned32 as return type and a Pascal string pointer for MapName.

Can anybody, with some more experience help me out here?

TIA

Peter
Peter
0 Kudos
Message 1 of 7
(3,594 Views)
hi

pAnsiChar is a Pascal datatype for strings ("Pointer to Array of Ansi Characters"). the first 8 bytes gives the length of the string as an integer, followed by the data as chars. labView can't handle this! there's a labview datatype "LabView string handle": 4 bytes (length as integer) followed by the data as char (quite near, but not the same). maybe you can create a PAnsiChar with typecasts to U8-Array and pass this array via "adapt to type" to your dll.

good luck!
chris
Best regards
chris

CL(A)Dly bending G-Force with LabVIEW

famous last words: "oh my god, it is full of stars!"
0 Kudos
Message 2 of 7
(3,594 Views)
On Wed, 27 Oct 2004 09:20:44 -0500 (CDT), chrisger wrote:

>hi
>
>pAnsiChar is a Pascal datatype for strings ("Pointer to Array of Ansi
>Characters"). the first 8 bytes gives the length of the string as an
>integer, followed by the data as chars. labView can't handle this!
>there's a labview datatype "LabView string handle": 4 bytes (length as
>integer) followed by the data as char (quite near, but not the same).
>maybe you can create a PAnsiChar with typecasts to U8-Array and pass
>this array via "adapt to type" to your dll.
>
>good luck!
>chris


Thanks for the info.
I will experiment some more.

Peter
Peter
0 Kudos
Message 3 of 7
(3,594 Views)
On Wed, 27 Oct 2004 18:55:23 +0200, Peter Oosterhoff
wrote:

>On Wed, 27 Oct 2004 09:20:44 -0500 (CDT), chrisger wrote:
>
>>hi
>>
>>pAnsiChar is a Pascal datatype for strings ("Pointer to Array of Ansi
>>Characters"). the first 8 bytes gives the length of the string as an
>>integer, followed by the data as chars. labView can't handle this!
>>there's a labview datatype "LabView string handle": 4 bytes (length as
>>integer) followed by the data as char (quite near, but not the same).
>>maybe you can create a PAnsiChar with typecasts to U8-Array and pass
>>this array via "adapt to type" to your dll.
>>
>>good luck!
>>chris
>
>
>Thanks for the info.
>I will experiment some more.
>
>Peter
>Peter


I
could not get it to work in Labview.
So I finally used Visual Basic (YUK!) to get it done. At least it did
not have any problems with the used data types.


Peter
0 Kudos
Message 4 of 7
(3,594 Views)
Hi Peter,

Have you read the following tutorial: An Overview of Accessing DLLs or Shared Libraries from LabVIEW?

If you post the DLL and the header file, maybe we will be able to help you. The VB code will also make helping you easier.


�Just in case you are still interested in calling the DLL with LabVIEW.

Best regards,
Philip C.
Applications Engineer
National Instruments
www.ni.com/ask
- Philip Courtois, Thinkbot Solutions

Thinkbot Solutions
0 Kudos
Message 5 of 7
(3,594 Views)
On Fri, 29 Oct 2004 18:24:17 -0500 (CDT), "Philip C."
wrote:

>Hi Peter,
>
>Have you read the following tutorial:
>href=http://zone.ni.com/devzone/conceptd.nsf/webmain/B26A875ACA51C567862567CA0055FF24?opendocument>...
?
>
>If you post the DLL and the header file, maybe we will be able to help
>you. The VB code will also make helping you easier.
>
>
>�Just in case you are still interested in calling the DLL with
>LabVIEW.
>
>Best regards,
>Philip C.
>Applications Engineer
>National Instruments
>www.ni.com/ask

Hi Philip (according to your sig you must be the cavalry)

It was a one time job, so I am OK now, after doing it in VB.
It would however be interesting to know how it should have been done
in Labview. I already seen the tutorial, but I could not find the
right information.
My impression is that what I needed was a double char pointer
( char**).
I just could not find a way to do that in Labview, but please tell me
if I am missing something.

The DLL is an API for OziExplorer. Together with some examples it can
be downloaded from www.oziexplorer.com:
http://216.218.220.254/oziapi/oziapi_examples.zip

Technical info on the API:
http://216.218.220.254/oziapi/oziapi_docs.html

The function I was trying to call:
function oziLoadMap(var MapName:pansichar):integer;stdcall;

My guess is that I need to use stdcall(WINAPI).
Return is int32.
MapName is ?????

I could get it to work for functions from the same DLL that returned a
pansichar, but for some vague reason the author chose to pass the
variable by refernce instead of value.
in the C-example code in the zip you can see that this is a char**.

I tried about every combination, but i could not get more than
'excpection occured in the external application' or a message from the
other application that it could not find the file 'q234sgvsfv]
p=Ѧ?' (just non-sense).

In VB it was just:


Declare Function oziLoadMap Lib "oziapi" (ByRef Filename As String) As
Long
Dim MapName As String

LoadMap(MapName)


It worked like a charm.

If you got an answer; I am ready to learn.

Peter
Peter
0 Kudos
Message 6 of 7
(3,594 Views)
Peter,

Please try the call specified in the attached images. I tried this and didn't get the error anymore.

Best regards,
Philip C.
Applications Engineer
National Instruments
www.ni.com/ask
- Philip Courtois, Thinkbot Solutions

Thinkbot Solutions
Download All
0 Kudos
Message 7 of 7
(3,594 Views)