Jump to content

Linking a LabVIEW DLL with VISSIM32.LIB


Recommended Posts

Hi there,

I would like to write a DLL with LabVIEW. The purpose of this DLL will be to act as a (shared memory) repository to allow data to be exchanged between my LabVIEW program and a VisSim program. (up until now I have used DDE to do this, but I would like to change the approach for a no. of reasons that I won't get into now)

Before I get into discussions about the finer details (i.e. UI thread, reentrant, mutex protection etc) I need to know if I can actually compile this DLL using LabVIEW so that VisSim gets what it needs.

Below you can see an extract from the VisSim user manual explaining how to write 3rd party DLLs that VisSim can call. It mentions .LIB and .OBJ files. When I have previously compiled DLLs using LabVIEW I have never needed to link in .LIB or .OBJ files before. Is that even possible with LabVIEW? If it isn't then can I just create an OBJ file from LabVIEW and link that to VISSIM32.LIB using another compiler ? (BTW the attached diagram shows a 'custom dialog box' which I don't need to use)

regards

Peter

P.S. this post is referred to from Info-LabVIEW (digest) on 07/04/07

The attached diagram shows how files are processed to create VisSim DLLs. This diagram steps you through the process of creating a DLL from a C source file; however, you can also create DLLs in Fortran, Pascal, and C++.

The main steps in the creation of VisSim DLLs are:

1. Create or edit an existing C, Fortran, or Pascal source file.

2. Create a project DLL for your compiler.

3. Execute a build operation, which compiles your source code into an object file.

4. Link the object file with VISSIM32.LIB to produce a DLL.

5. VisSim also provides a DLL Wizard that automatically performs steps 1, 2, and

4. For directions on using the DLL Wizard, see page 406.
Criteria for writing DLLs

You can write DLLs in any language, provided the language has the following

capabilities:

• 64-bit floating point array parameters

• Pointers to 16-bit integers

• _stdcall calling conventions (default for Microsoft Fortran and Delphi

Pascal)

Example DLLs written in C, Fortran, and Pascal are distributed with VisSim and

reside in subdirectories under the \VISSIM60\VSDK directory.

Link to comment

QUOTE(PeterB @ Jul 3 2007, 11:49 PM)

Hi there,

I would like to write a DLL with LabVIEW. The purpose of this DLL will be to act as a (shared memory) repository to allow data to be exchanged between my LabVIEW program and a VisSim program. (up until now I have used DDE to do this, but I would like to change the approach for a no. of reasons that I won't get into now)

Before I get into discussions about the finer details (i.e. UI thread, reentrant, mutex protection etc) I need to know if I can actually compile this DLL using LabVIEW so that VisSim gets what it needs.

Below you can see an extract from the VisSim user manual explaining how to write 3rd party DLLs that VisSim can call. It mentions .LIB and .OBJ files. When I have previously compiled DLLs using LabVIEW I have never needed to link in .LIB or .OBJ files before. Is that even possible with LabVIEW? If it isn't then can I just create an OBJ file from LabVIEW and link that to VISSIM32.LIB using another compiler ? (BTW the attached diagram shows a 'custom dialog box' which I don't need to use)

Well if you create a DLL you always link with lib and/or obj files unless you never use any library functions, be it LabVIEW External Code functions, C runtime functions, or Windows API functions. But in Visual C you don't need to specify the C runtime library and Windows API import library specifically since most of them are added by default to a project and the Visual C linker picks from them whatever he needs.

An obj file is the compiled form of a single .c or similar file and a lib file is just a collection of several obj files. EXEs and DLLs are the combination of all obj and lib files with some extra startup stub and possibly resources and other custom stuff put into.

Basically you want to add your custom library file to your project somehow. You can do this by adding it explicitedly to the files that your project consists of, or in the project settings add the name of the library under Linker Settings and also provide a path to the directory where Visual C can find that library.

Rolf Kalbermatter

Link to comment

QUOTE(rolfk @ Jul 4 2007, 03:37 PM)

Well if you create a DLL you always link with lib and/or obj files unless you never use any library functions, be it LabVIEW External Code functions, C runtime functions, or Windows API functions. But in Visual C you don't need to specify the C runtime library and Windows API import library specifically since most of them are added by default to a project and the Visual C linker picks from them whatever he needs.

An obj file is the compiled form of a single .c or similar file and a lib file is just a collection of several obj files. EXEs and DLLs are the combination of all obj and lib files with some extra startup stub and possibly resources and other custom stuff put into.

Basically you want to add your custom library file to your project somehow. You can do this by adding it explicitedly to the files that your project consists of, or in the project settings add the name of the library under Linker Settings and also provide a path to the directory where Visual C can find that library.

Rolf Kalbermatter

Thanks for your reply Rolf, but I still don't get it :question:

In the LabVIEW project manager in the build specifications section (not from within Visual C etc), where do I specify to link in the VISSIM32.LIB file prior to compiling my LabVIEW shared library (DLL) under LabVIEW ?

regards

Peter

Link to comment

QUOTE(PeterB @ Jul 4 2007, 07:50 AM)

Thanks for your reply Rolf, but I still don't get it :question:

In the LabVIEW project manager in the build specifications section (not from within Visual C etc), where do I specify to link in the VISSIM32.LIB file prior to compiling my LabVIEW shared library (DLL) under LabVIEW ?

You don't! LabVIEW can NOT do anything with lib and obj files. That is for C compilers only and even then you have to have lib and obj files that are compatible for your C compiler, eg. meaning they should have been created by the C compiler you want to use them with too. You can't create a LabVIEW DLL and hope that LabVIEW will link to your lib file magically. A LabVIEW DLL is really a LabVIEW LLB with very small exported C wrappers around those VIs inside the LLB. There is no way you can influence the C wrapper generation made through the LabWindows CVI runtime engine to somehow include your lib file and even if you could it wouldn't help either, as the wrapper code generation does not know how to link to other lib files than what is necessary to wrap the VIs such that they can be called as a DLL export function.

If this lib file is only an import library to the actual functionallity in a DLL then you could instead link to that DLL through the Call Library Node. Otherwise there will be no way around creating some C code to be put in a DLL and that can be called by LabVIEW that links with your lib file. In that case you need to create a DLL in Visual C, that you can call from LabVIEW and you want to include that lib file into that Visual C DLL project.

I hope I didn't confuse more than help but it's simple! If the actual functionality of your lib file is not located in a DLL file for which you have documentation and the API interface, then you WILL have to create a C DLL first.

Ok I reread the first post once more and I see that you want to create a DLL to be integrated in VisSim and that the DLL needs to link to vissim32.lib. This can't work without Visual C. In fact their statement that any environment that can create DLLs should work is mostly wrong. Besides Visual C there is only LabWindows CVI and proabably Borland C that can directly link with vissim32.lib. lib and obj files are binary files that can come in many flavors and Visual C will generate and require so called COFF format, while Borland will generate and prefer OMF format. LabWindows CVI used to support both formats for generation and linking but you needed to decide whith format you wanted during installation. LabVIEW can not generate obj files. What it can and does do is generating Visual C compatible import libraries for the LabVIEW generated DLLs. So what you can do if you need to generate Vissim callable DLLs that incorporate LabVIEW code is to generate the LabVIEW DLL and then generate another C DLL that also includes the lib file for vissim32.lib and your LabVIEW DLL import lib file.

Rolf Kalbermatter

  • Like 1
Link to comment

QUOTE(rolfk @ Jul 5 2007, 01:26 AM)

So what you can do if you need to generate Vissim callable DLLs that incorporate LabVIEW code is to generate the LabVIEW DLL and then generate another C DLL that also includes the lib file for vissim32.lib and your LabVIEW DLL import lib file.

Rolf Kalbermatter

Excellent ! I'm glad you came up with a solution for me :thumbup: . Thank you indeed for elucidating the situation Rolf.

regards

Peter

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.