Creating dll, lib, fp's to be used in other CVI programs

Disclaimer: I am a self-taught CVI (and C) programmer in which I learned from examples, NI forums, and google  
Main question: What is the proper way to create a dll, lib, and fp to be used in other CVI programs?  What I am doing is creating a "wrapper class" called PowerSupplies (and other wrapper classes) that takes arguments from the user and call the correct functions based on the power supply model type.
Inside my Power Supplies project, I have included each power supply's function panel.  In the C file, I have added my functions and include file.  for example, here's one
int _VI_FUNC Supply_InitSupply (int devs, char *resourceName, int IDQuery, int resetDevice, int *instrumentID) {
switch (devs) {
case AG663XXA:
return ag663xxa_init(resourceName,IDQuery,resetDevice,instrumentID);
case HPE364XA:
return hpe364xa_init (resourceName, IDQuery, resetDevice, instrumentID); //Has Voltage and Current
return -1;
and then of course at the bottom, there resides the DllMain and DllEntryPoint functions.  What the heck are these, and am I suppose to rename these?  I ask because I created another wrapper classes with DMM's and I get the Multiply Defined Symbol Error with these two functions when using together in a separate program.
Additionally, I have created a header file, which can be included in other CVI programs to know what functions there are.  I noticed I could "Generate Prototypes" after the fact and wasn't sure if this was the correct way or not.  My header file is below:
#ifndef __PowerSupplies_H__
#define __PowerSupplies_H__
#ifdef __cplusplus
extern "C" {
#endif
//==============================================================================
// Include files
#include "cvidef.h"
#include "ivi.h"
//==============================================================================
// Constants
#define POWER_SUPPLY_ENUM_FACTOR 200
typedef enum
AG663XXA = 200,
HPE364XA
} power_supply_type;
static IviStringValueTable power_supply_table =
{AG663XXA, "AG-663##X"},
{HPE364XA, "HP-E364#A"}
//==============================================================================
// Types
/************** Static Function Declarations **************/
/************** Global Variable Declarations **************/
/************** Global Function Declarations **************/
int _VI_FUNC Supply_InitSupply(int devs,char *resourceName, int IDQuery, int resetDevice,int *instrumentID);
/*commented out long list of functions for this forum's sake*/
int _VI_FUNC Supply_Close(int devs, int instrumentID);
int __stdcall DllMain(HINSTANCE hinstDLL,DWORD fdwReason, LPVOID lpvReserved);
int __stdcall DllEntryPoint(HINSTANCE hinstDLL,DWORD fdwReason, LPVOID lpvReserved);
#ifdef __cplusplus
#endif
#endif /* ndef __PowerSupplies_H__ */
I then have built it as a static library and dynamic link library.  I then generated a Function Panel from the header file with Prefix Supply_ and Qualifier as _VI_FUNC.
All worked nice and dandy, copied files to appropriate places in the IVI directory.
In my other CVI program in which uses these "wrapper classes", I have included the function panel's that I created.
Well with the error i mentioned above about Multiple Defined Symbol, I have come here to figure out what went wrong.
What are the DllMain and entry point functions?
Is my c and h files created correctly with proper prefixs?  I tried extern once, and got errors I believe.
Does the function panel use the .lib files? Am I going about this correctly or is there an easier/more efficient way?
Any and all advice is greatly appreciated!!!
Thanks!

There's info in the CVI help on how to make DLL,s in CVI.
There's quite a bit more to it than you might imagine at first.
I've pasted a DllMain that I wrote.
Some key issues:
You can put a type library into your DLL, that way if you add the DLL as a reference in Visual Studio, VS will know the prototype without your having to bring in a header file or import library of any kind.
CVI created DLL's are not "active" DLL's and should not be registered with regsvr32, this will just make a mess.
You can tell CVI what you're exporting in a couple of different ways, I always use "symbols marked for exports"  and use the macros DLLEXPORT DLLSTDCALL, but NI says using a header file is preferable, I forget why.
The DLL search path is a wonderful thing - it's easy to wind up using a different copy of the DLL than you intended due to the way windows searches for the DLL.  Different versions of windows have slightly different rules.  Some allow redirection to help you manage the search path.
CVI will not automatically switch between debug and release versions of the import library - you have to call out the correct version in your project and link it to any executable using it. 
You can do "dynamic" loading / linking of a CVI DLL without binding to an import library using GetProcAddress function, but it's easier to use the import library.
A DllMain isn't necessary but is good practice.
Good luck.
/*== PRAGMAS =====================================================================================================*/
#if defined (_CVI_) && (_CVI_ >= 850)
  #if defined _CVI_DEBUG_
    #pragma C99_extensions_on  
  #endif
#endif
/*== INCLUDE FILES ===============================================================================================*/
#include <windows.h>
#include <userint.h>
#include <ansi_c.h>                                                                                     
#include <cvirte.h>
#include <stdio.h>
#include <utility.h>
#include <analysis.h>
#include <toolbox.h>
#include <formatio.h>      
/*== MACROS ======================================================================================================*/
#define MAX_STRING_SIZE 256   
#define MAX_MESSAGE_SIZE 256
#undef  MAX_LOG_MESSAGE_SIZE
#define MAX_LOG_MESSAGE_SIZE 256                                                
#undef  WriteFile   // To deconflict formatio (CVI) version of this function
#undef  ReadFile    // To deconflict formatio (CVI) version of this function             
/*== TYPEDEFS ====================================================================================================*/
// Data type providing reference structure for thread local storage (TLS).
typedef struct ThreadData {
  CHAR ErrorString[MAX_STRING_SIZE];
} ThreadData, * LPTHREADDATA;
/*== MODULE SCOPE VARIABLES ======================================================================================*/   
static FILE * logFileStream;                      
static HANDLE hModule = INVALID_HANDLE_VALUE;
/*== GLOBAL (HEAP) VARIABLES =====================================================================================*/
// TLS index
DWORD g_dwTlsIndex;
/*== PROTOTYPES ==================================================================================================*/    
/*== CODE ========================================================================================================*/  
* Function: DllMain
* Description:
*    DLL Main entry point.  Provides for DLL initialization.  
* Limitations:
* Parameters:  System defined.
* Return Value:
BOOL WINAPI DllMain (HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved) {
  LPTHREADDATA lpThreadData;      
  switch (fdwReason) {
    case DLL_PROCESS_ATTACH:
      // Allocate a TLS index.
      if ((g_dwTlsIndex = TlsAlloc ()) == 0xFFFFFFFF) return FALSE;
      hModule = hInstDLL; 
      // No break - fall through and initialize for main thread
    case DLL_THREAD_ATTACH:
      lpThreadData = (LPTHREADDATA) calloc (1, sizeof (ThreadData));
      if (lpThreadData != NULL) TlsSetValue (g_dwTlsIndex, lpThreadData);
      lpThreadData = TlsGetValue (g_dwTlsIndex);
      lpThreadData->ErrorString[0] = '\0';     
      break;
    case DLL_THREAD_DETACH:
      // Release the allocated memory for this thread.
      lpThreadData = TlsGetValue (g_dwTlsIndex);
      if (lpThreadData != NULL) free (lpThreadData);
      break;
    case DLL_PROCESS_DETACH:
      // Free the allocated memory for this thread (main thread).
      lpThreadData = TlsGetValue (g_dwTlsIndex);
      if (lpThreadData != NULL) free (lpThreadData);
      // Release the TLS index.
      TlsFree (g_dwTlsIndex);
      break;
  return TRUE;
} // end, DllMain
INT DLLSTDCALL DllEntryPoint (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
  // Included for compatibility with Borland
  return DllMain (hinstDLL, fdwReason, lpvReserved);
} // end, DllEntryPoint
implement dll functions like this:
int DLLEXPORT DLLSTDCALL myFunc (int iParam) {
  return 1;

Similar Messages

  • How to create dll file from c code to use in compactrio 9004 RT controller

    Hi.
    I am using Compactrio 9004 Real time controller and i am new to this. I have a C code and i want to use this with the RT controller.I red that that can be done by creating a dll file and can be called in labview.Can any body expalin how to create a DLL from the c code and be used with this RT controlelr?
    Regards,
    Vishnu

    vishnu123 wrote:
    Hi,
    Earlier in this forum itself in cRIO 900x controllers will run Pharlap and run C/C++ code compiled into .dll files.Can you please tell how to transfer the created DLL to RT controller memory throght FTP?
    Thanks and regards,
    Vishnu
    There is another KB article about this for Pharlap based controllers. And you are right the earlier CompactRIO controllers were Pharlap based. Basically for a deployed application to work, you need to put the DLL through FTP in "/ni-rt/system". If you deploy it directly from the project everything will be loaded into memory through the project environment itself including directly dependable DLLs, (but of course won't survive a power cycle).
    I hope you are aware that while Windows DLLs can work on Pharlap OS they by no means will do so always. The Pharlap OS has not a fully featured Windows API. Also you need to be careful which version of Visual C you are going to use depending on the Pharlap OS version, since the VC runtime DLLs already present on the controller will need to be the same as the ones your Visual C environment likes to link in. Recent Pharlap OS versions use the msvcr71.dll. It's very possible that those runtime libraries can't just simply be copied from a normal Windows installation but might have been recompiled by NI specifically for their controller targets.
    So to avoid problems it's a good idea to make sure your DLL uses the same runtime library DLL or make your DLL to include the static MS runtime.
    Rolf Kalbermatter
    Message Edited by rolfk on 02-05-2008 09:51 AM
    Message Edited by rolfk on 02-05-2008 09:53 AM
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • When you've created a jar file, how do you use images in your program

    i want to be able to play a game with a jar file, but the image path file gets screwed up

    >
    i want to be able to play a game with a jar file, but the image path file gets screwed up>To get a reference to a resource isnide a Jar file?
    URL url = Thread.
      currentThread().
      getContextClassLoader().
      getResource("path/to/the/image.gif");Where path/to/the/image.gif is the relative path within the Jar.
    As an aside, JAI is a separate API for doing advanced stuff with images, and it supports image formats unknown to the J2SE. Whereas your question was better suited to a 'New to Java' style group, especially since it seemed the question had to do with paths, more than images as such.

  • How can I get the mouse cursor from acrobat reader to use in other windows programs?

    I like the pointer used in Adobe's Acrobat Reader and would like to use it as my regular mouse pointer. A friend and I were able to do it years ago, but I can't now. I am using Windows XP Home Edition.
    Resveratrol

    Reader Forum http://forums.adobe.com/community/adobe_reader_forums
    Or, maybe
    Acrobat SDK Developer Forum http://forums.adobe.com/community/acrobat/acrobat_sdk

  • Help creating .dll with c using JNI

    Hi. I have created a JNI application that uses C to call Java. Now, I am trying to create the .dll for windows. I am using VS C++ compiler. My program compiles; however, it doesn't seem to start the JVM. I am not sure how to pass the arguments in VS C++ while builiding and running. Please let me know. Thanks.

    Hey,
    Thanks. I apologize for not being clear. I have created the dll file and an application that links to that dll and executes the code. It creates the .exe file and when I execute it, it goes through the sample() function that just prints "Hello", and then it goes through the startJVM() function where the JVM is intended to start; however, the status of JVM is returning -1. It's not able to start JVM. I have included the path for the jvm.dll and jvm.lib. But, still won't work. Please reply with suggestions/comments. Thanks again.

  • Trying to create DLL from VI to use in TestStand.

    I trying to create a DLL out of an existing VI file.  The VI has about 4 inputs and about 3 outputs.  If I go to Tools >> Build Application and select the Build Target as a "Shared Library (DLL)" i get a dll after the build; but when I try to call that DLL from teststand, it doesn't recognize any of the inputs or outputs.  How do I build a DLL so that teststand will reconize the inputs and outputs?
    Solved!
    Go to Solution.

    The controls and indicators are connected to the connectors.  Also, answering an earlier post, the prototype information for the inputs and outputs are not automatically displayed. I can manually define the prototypes, but then the question is how does each prototype link to its corresponding parameter (by name?). I've also tied creating just a simple VI that has just one string input and one string output.  I built the VI to a DLL and tried calling in TestStand and i get the same results.  I've inserted the resulting header file after that build.  Which, by the way, looks exactly like my other created DLL's header file.  The difference in bold(the name of the VI). Which makes me thik that my build DLL process might be off.
    #include "extcode.h"
    #pragma pack(push)
    #pragma pack(1)
    #ifdef __cplusplus
    extern "C" {
    #endif
    void __stdcall String_input_output(void);
    long __cdecl LVDLLStatus(char *errStr, int errStrLen, void *module);
    #ifdef __cplusplus
    } // extern "C"
    #endif
    #pragma pack(pop) 

  • How to create dll in Visual Studio 2008 in Visual C++

    Hello,
    I have insatlled Visual Studio 2008. I have to create DLL in Project
    type Visual C++.
    Which Template i have to select to reate dll, MFC DLL or Class
    Library?.
    I have to call or import this dll in Windows Forms Application. How
    can i do this. Please give details procedure to do this.

    If we look at how  AFX_CLASS_EXPORT and AFX_CLASS_IMPORT  are defined in afxv_dll.h we see the following.
    #define AFX_CLASS_EXPORT __declspec(dllexport)
    #define AFX_CLASS_IMPORT __declspec(dllimport)
    So, when exporting our classes from our DLL we want the class declarations from the DLL to look like this:-
    class __declspec(dllexport) CMyClass : public CObject
    And, when importing our C++ classes into our application we want the class declarations from the DLL to look like this:-
    class __declspec(dllimport) CMyClass : public CObject
    OK, so here's how I do things.
    In the stdafx.h file for the export DLL, include two #defines at the bottom of the file like this:-
    #define _MYLIB_DLLAPI_
    #define _MYLIB_NOAUTOLIB_
    Now, in the main header file for your DLL, say mylib.h (the main 'point of entry' header for your DLL that you will include in you application later), add the following at the top:-
    // The following will ensure that we are exporting our C++ classes when
    // building the DLL and importing the classes when build an application
    // using this DLL.
    #ifdef _MYLIB_DLLAPI_
        #define MYLIB_DLLAPI  __declspec( dllexport )
    #else
        #define MYLIB_DLLAPI  __declspec( dllimport )
    #endif
    // The following will ensure that when building an application (or another
    // DLL) using this DLL, the appropriate .LIB file will automatically be used
    // when linking.
    #ifndef _MYLIB_NOAUTOLIB_
    #ifdef _DEBUG
    #pragma comment(lib, "mylibd.lib")
    #else
    #pragma comment(lib, "mylib.lib")
    #endif
    #endif
    Now, just declare all the C++ classes you want exported from the DLL like this:-
    (Note: Any C++ classes not declared with MYLIB_DLLAPI will not be exported from the DLL)
    class MYLIB_DLLAPI CMyClass : public CObject
    regards,
    Matt John
    complete variety of quilts is availabale here!
     PR: wait...
     I: wait...
     L: wait...
     LD: wait...
     I: wait...
    wait...
     Rank: wait...
     Traffic: wait...
     Price: wait...
     C: wait...

  • Create .dll

    i don't know how to create dll file, which i want use to link with another file(.lib), any one can help? thanks in advance!

    You need a C++ compiler.Linker, you meant. Which he probably has... I'd say what he needs is the documentation for that linker which will tell him the correct flags for generating a shared lib.

  • Calling LV created DLL from LV

    Howdy-
    I'm trying to call a LV DLL from within LV (seperate project).  Once the DLL has been comppiled I'm using the Import Shared Library to create the node.
    However when I try this I get an error message with the import that appears to have trouble with LVBoolean and int32_t.
    I've created a simple DLL (adds a DBL to an INT 32 and creates a Bool when the sum is > 0). 
    Compiling this DLL and trying to import it has the same issue.
    Any clues?
    Attachments:
    Import Shared Lib.png ‏49 KB
    My DLL.zip ‏34 KB

    nathand wrote:
    This does mean LabVIEW will create the datatypes with U8 instead of booleans, which you can replace yourself with a boolean after importing.
    Except that the Call Library Node doesn't allow for configuration of an explicit boolean type (for obvious reasons as there is no standardized boolean datatype in C before C11 and even then the standard says nothing about if it should be a byte or the prefered integer size for the current platform or anything else). LabVIEW then uses Adapt to Type instead, which forces the skalar parameter to be always passed by pointer!
    Most simple solution is to still use an explicit integer that is properly sized and convert between the LV Boolean and the integer on the diagram.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • How to create PDF from Excel with Password Protection Using Visual Studio & Visual Basic

    Could someone provide some VB code sample(s) to create a PDF file with password protection (Security Method - Password Security - Restrict Editing & Printing)?
    I create a bunch of reports every week using an Excel 2010 addin that subsequently must be printed to PDF.  I then have to manually edit the properties of each document in order to apply the printing restriction.
    I'm using Acrobat X.
    I've downloaded the SDK but have no idea which dll's to use or where to begin.
    Thanks!
    Ross

    That's surprising & disappointing.  I would have thought that this capability would have long since been requested.
    Thanks for the heads up.

  • Creating dll and calling it in labview crashing the program

    Hi All,
    I am using labview from quite a long time.But this time i am stuck with dll.Not able to solve this issue.
    I have to communicate with FTDI chip.
    I have a VC++ Project to communicate with SPI of FTDI.That Code is working perfectly fine.
    Now I Have to automate that through LabVIEW. VISA Drivers i cant use in this. So Last option left is either to create dll or to make EXE out of it.
    I have tried by creating DLL and then calling it in LabVIEW by using Call Library Function Node.But its not helping me out every time LabVIEW is getting Crashed.
    Is there error in creation of dll or something i am not doing properly while calling?
    Thanks In Advance 
    Shweta
    Attachments:
    old_dolphin_sub_spi_func_ftdi.c ‏21 KB
    ftdi_write_read.vi ‏15 KB

    Which function call crashes LabVIEW?
    Have you tried switching the calling convention from stdcall to C for all of the DLL calls?
    Why are you converting a string to a number, instead of using a numeric constant directly? If you want a number in hex, you can right-click a numeric constant, make the radix visible, and switch it to hex display.

  • Creating dll in Labview

    Hello All,
    How do i create a dll in labview? I want to use it as a plug in into an application.
    Demmy

    Hi Demmy
    What LabVIEW version are you using? If you are using version 8 and higher then you have to have your VIs loaded into a LabVIEW project and you use the project build specification. You can access the LabVIEW 2009 help on how to build a dll here.
    Here is a quick summary:
    In the project window right click build specifications and choose New -> Shared Library (DLL). This will open the window to create the dll.
    Go to the Source Files category and use the arrow to take the VIs that you want into exported VIs, a dialog will then come up to define the function prototype for that vi. Do this for each vi you want to access in your dll.
    You will need LabVIEW professional version to create dlls and the target computer where you are using the dll must have the LabVIEW run time engine installed.
    Message Edited by Karissa on 03-03-2010 09:05 PM
    Systems Test Engineer
    Certified LabVIEW Architect (CLA)

  • Create dll with arrays and call it

    I am trying to create dll with labview in order to pass a 2d array to the main program. The problem is that I don't really know how to create the function to call it (I don't know much about pointers)
    The function I have created to call the dll is void Untitled1(TD1Hdl *Array1) which is suposse to return the array created on it.
    For example, in the program attached, how should I do to pass the array to another program using dlls?
    Thanks a lot,
    Juanlu
    Attachments:
    Untitled 1.vi ‏7 KB

    The code you've provided doesn't do anything (just a control wired to an indicator) so I'm not sure what you're asking here.
    If I understand correctly, you want to build a DLL from your LabVIEW VI.  From what language will you call that DLL?  There is no standard way to pass a 2-D array.  If you can convert to a 1-D array, you can use a simple pointer.  With a 2-D array, you're stuck with LabVIEW's array representation (the TD1Hdl type), which means that whatever code calls that function will need to understand the LabVIEW data type and how to manipulate it.

  • Asynchronuous functions don't work in a C# dll used by a CVI application

    Hello,
    I have an existing application written with CVI 9.0.1, which have to interact with a C# 2010 dll (which doesn't have any window) via a CVI<->.net wrapper (created using the usefull .net controller of CVI).
    This C# dll uses asynchronuous functions, like NetworkStream.BeginRead() and EndRead() functions of a System.Net.Sockets.TcpClient object for example.
    These asynchronuous functions work fine when the C# dll is used by a C# application (having a main window) or when the C# dll is converted in a standalone C# program (having a main window with buttons, to call its methods, just to try), but asynchronuous functions don't work when my C# dll is called by my CVI application (which is my goal): execution stays inside NetworkStream.BeginRead() for example (for the concerned thread).
    NetworkStream.BeginRead() can be successfully bypassed by using the synchronuous function NetworkStream.Read() instead, but the C# dll uses others asynchronuous functions wich have no associated synchronuous functions.
    Here is a portion of C# code (I don't have the source code for the Snmp object ; got_trap() method is never called when asynchonuous calls don't work):
    public void run() // the thread
     Snmp snmp = null;
     try
      snmp = new Snmp(true);
      snmp.NotifyListenPort = 162;
      snmp.NotifyRegister(null, null, new NotifyCallback(got_trap), CB_DATA_);
      isActive = true;
      Thread.Sleep(Timeout.Infinite);
    Thinking it could be a problem with window messages which could be not processed (in the C# dll), I tried to replace the Thread.Sleep(Timeout.Infinite) instruction, in the code where the asynchronuous management take place, by a window creation plus my Win32 window message loop, but asynchronuous functions don't work better (whereas my loop seems to successfully process messages):
    Form myForm = new Form(); // an empty window
    myForm.Show();
    int bRet;
    MSG msg = new MSG();
    while ((bRet = GetMessage(out msg, IntPtr.Zero, 0, 0)) != 0)
        if (bRet == -1)
           // handle the error and possibly exit
        else
          switch (msg.message)
            default: // everything else
            TranslateMessage(ref msg);
            DispatchMessage(ref msg);
            break;
    Any idea ?
    Thank you,
    rvfr.
    Solved!
    Go to Solution.

    Solved: in fact, the snmp assembly that I was using just needed to be dotNet registered.
    rvfr.

  • How to create dll with visual c++ 6.0

    I have create two file ( file.h, file.cpp)
    I make a new project in visual c++ 6.0, to make dll wizard.
    and then I add code (file.h, file.cpp) in this project. But when i build it has a error.: fatal error C1010: unexpected end of file while looking for precompiled header directive.
    help me...

    Hi,
    For me, when I make the .dll file with Visual C++, I used the cl.exe to do the job. Open the dos command, type cl then see the option, you should soon find out the solution, for futher question, you can email me at [email protected] and I will reply you as soon as possible.
    With my best,
    Zike Huang(jim)

Maybe you are looking for