Problem calling LabVIEW DLL with c#

Dear all,

I compiled a few DLLs in LabVIEW and called these DLLs using c#.
I'm having trouble passing in strings and arrays as input and output of the DLL.

Whenever I try to view the string I have entered in a dialog box (this part is written in LabVIEW DLL), a LabVIEW message dialog box appears and the program just stuck there.

Whenever I try to enter a string or an array to the dll, Microsoft Visual Studio would display "attempt read or write protected memory. It is often an indication that other memory has been corrupted. »

I attached the vi and also the c# .sln file.

Can you guys please advise where am I wrong?

Thank you very much.

You must allocate strings and arrays of output!

private void button1_Click (object sender, EventArgs e)
{
output string;
int [] value;
StringOutput ("A", "B", exit, 3, value, 4);
}
}

Your variable output and value must be preallocated to ensure storage of 3 items respectively. 4. and since you want to receive the C string that you need to increase this to 4 characters terminated by a NULL value.

String in c# is also a not a C string of object pointer. You must declare the StringOutput() function as follows:

[DllImport("SharedLib.dll",CallingConvention=CallingConvention.StdCall, Charset=CharSet.Ansi]internal static extern int StringOutput(StringBuilder A, StringBuilder B, out StringBuilder StringOutput, int sizeString, out int[] output, int sizeArray);

Then call like this:

StringBuilder output = new StringBuilder(4);int[4] array = new int[4];

StringOutput("A", "B", output, output.Capacity, value, value.Length);

Please note that I'm not a pro in c# and usually do not do much in it. Also that this code has not been tested or updated at all, so probably contains some errors. He however point you in the direction of where to look further.

What you need to understand, is that the C DLL that you created in LabVIEW has a so-called unmanaged interface. This means c# is not able to know how to manage the memory for the parameters at all and you have to do everything yourself, where the obligation to explicitedly initialize variables output and table with a block of memory préallouée.

Tags: NI Software

Similar Questions

  • Problem calling seconday DLLs in labview

    Hello

    I'm using Labview 8.6 for my application. The application calls a dll developed in vc ++ (main dll).  During execution of the application, the main dll(vc++) calls another (secondary dll) developed in vb 6.0 dll.

    During the process, the main dll sends data to secondary dll to display data in a pop-up window. After getting the user recognize the display, the vi application stops.

    When the application runs first time (the vi running first time after labview open), the data sent by the main dll are updated in view of the secondary DLLs. But, for the second time from new data of the main dll not are not updated in view of the secondary DLLs.

    Once again, after the closure of the vi and quit labview, if I open and run the vi, then the data of the main dll are updated in dll secodary display. But the maindll data must be updated in the secondary dll without leaving labview.

    I use "Function Call Library" to call the maindll.

    Can someone please give the remody to this problem...

    Thanks in advance.

    Swamy.

    Is - this two dll to reside in the same physical directory as your main vi? They are included in your project?

    -AK2DM

  • (UN) Managed Wrapper calling LabView-Dll

    Hello

    I'm focused with a strange behavior that I couldn't explain.

    I had to extend the NI272x in my environment unmanaged c++ to a StepType http://sine.ni.com/cs/app/doc/p/id/cs-11443/lang/de/pdf/yes/pdf that descripes a functional testsystem.

    Provieds let us OR no C Api for this devices. But the LabView drivers were available. So I did LabView Wrapper
    to consume. It worked well.

    Current development of extension is done in c#. During execution, it loads the unmanaged Dll StepType old. If the Dll of LabView is
    used. I'm not able to load the DLL with c# via LoadLibrary SDK to memory.

    To understand what is happening I have provied a small project that descripes the task.

    Concerning

    Jürgen

    I think that the problem is that the dll you load dependent DLLS. The normal behavior of the LoadLibrary does NOT automatically search the dependent DLLs in the same directory as the dll you are loading. You must instead use LoadLibraryEx with the LOAD_WITH_ALTERED_SEARCH_PATH option (it's what teststand uses when loading DLLs with adapter c ++). See info on help from Microsoft on MSDN for details on LoadLibraryEx and LOAD_WITH_ALTERED_SEARCH_PATH.

    Hope this helps,

    -Doug

  • Generation of C++ with LabVIEW DLL error

    Hi, I am a student at the UC Irvine, learn how to use LabVIEW.  I'm working on a practice project for which I use a PID system to control the temperature of an object.  Things are starting to be a little awkward with the control statements nested, loops, etc., so I thought I have exported a LabVIEW DLL with all the difficult to encode things like interfacing with my instruments and tracing of data or something else and do the calculation and follow-up of the commands in C++.

    The DLL file I made in LabVIEW exploded without a hitch, as far as I can tell, but when it a link to my C++ test program (which at this point is just including the .h file of the LabVIEW for the DLL and an empty main() function), I get a lot of build errors.  I'm using Dev - C++ that uses g ++ to compile the code.

    Here is a picture of my build errors:

    Normal windows applications are not so forgiving on where you can put your DLL under LabVIEW. You must have a DLL or in the Active Directory where the executable file itself (this is your build directory, not the source directory), windows or directory system or any what directory defined in the PATH environment variable. Anythin else probably won't work, or at least not reliably.

    No need to add the cintools directory to your include paths or paths of the library file. You must only that if you decided to leave native LabVIEW DLL export data types, in which case you would need Manager of LabVIEW to prepare the correct data buffers.

    Rolf Kalbermatter

  • Call a dll built with Labview in Digital Micrograph

    Hello everyone,

    I am faced with a difficult problem. I use Digital Micrograph that run the DLL of enforcement. This DLL must be built with a structure of library written in C. In this C code, I can call a built with Labview VI. If the Vi is simple, Digital Micrograph is happy. But, if I include a graph in the VI, C code builds and create a dll but Digital Micrograph falls down. Of course, DM is unclear the type Labview graph. I can do what I want in my VI and how can I solve the problem?

    Thank you.

    Gautier

    gautierdufourcq wrote:

    I solved part of the problem, DM do not plant more but the Labview graph is not displayed. Do you have a solution? THX

    Is not a problem of LabVIEW.

    It's their DLL. Talk to DM.

  • Get the 1097 error when trying to call a Labview DLL

    I had to write a wrapper DLL to use some functions in the DLL to a third party, and I'm having a few problems. I created an executable to test my code and it works fine, but when I try to execute the same function in the DLL that I created in Labview, I get error 1097. I read through most of the posts on this forum about this issue, but none of the proposed solutions are working for me. I'm sure this isn't a question of transfer settings to COLD LAKE because I changed the function so it only accepts a single entry (a number he obtains from a Subvi, which came from the third-party DLL, this entry is working with a bunch of other functions, so I don't think that is the question).

    I have attached the C code that creates the wrapper, but I don't know how it is useful without familiarity with the functions of the original DLL. I hope that someone can spot something basic I am out of my code, but please let me know if I need to call something else.

    I use a Labview 32 bit version 2012 on a 64-bit Windows 7 computer.

    Thanks in advance for any help!

    You should read the documentation on LoadLibrary() and understand. Essentially if you provide a full path to LoadLibrary() the DLL MUST be present at this place so that LoadLibrary() will succeed. If you pass only the name Windows DLL will ONLY search in these places:

    (1) if the module (the DLL) is already loaded it will return a handle to the loaded module and increment its reference count

    (2) if the referencing module contains a manifest (either incorporated into the image module or in a separate manifest file in the same directory as the executablemodule) specyfying a version number for this DLL will load this DLL with this version of the SxS (side by side) location and failure if it is not present

    (3) if the executable load contains a manifest (either incorporated in the executable file or in a separate manifest file in the same directory as the executable file) number specyfying a version for this DLL, it will load this DLL with this version of the location of SxS (side by side) and fail if it is not present

    (4) it will search for the DLL in the same directory as the directory where the current image of the process is loaded. It is NOT the directory of the DLL loading the DLL, BUT the directory where the EXE file from which the process was created.

    (5) in the system directory

    (6) in the Windows directory

    (7) any directory in the PATH environment variable

    (8) the path of current directory which is a location managed by windows by process and changed the two explicitedly when the application calls the API SetCurrentDirectory() but also implicitedly by things like the file selection dialog whenever it is rejected by other means than the undo operation.

    Essentially putting your dependend DLL in the same directory as the wrapper DLL does NOT work when you use the name of the DLL only UNLESS you place the two DLLs in the same directory as your executable file. If you don't want this restriction and want to be able to move these modules together in different directories, you don't have to create the correct path in your wrapper to LoadLibrary(). Basically, you must have the code to determine the location of your DLL wrapper path and then strip her own name and add the DLL name wrapped in it and then move to the LoadLibrary().

    There are several ways to determine the path of the current module. The simplest if you don't mind having the name hard-coded in your code DLL would be to ask GetModuleFileName (GetModuleHandle ("yourDLLname"), buffer, size).

  • problems in C++ dll call

    Hi, I compiled a dll in C++ to write data in a shared data segment, and it works well in Labview. Then I try to call the Dll in C++, it can be built successfully, but will break in the end. I have this problem since almost a whole day and could not find the solution.

    Here are the source files for my Dll and the program calling dynamically.

    DLL:

    Calling program.

    Problem solved.  The work for Labview and C++ dll must be like that. The shared data segment must also be declared as funtion and with 'extern 'C' ' coming. In addition, Labview can read only pointers from dll.

  • TestStand do not call a Labview DLL copied to a new location.

    TestStand v4.2 & v8.6.1 LabVIEW: I have a problem with TestStand calling a Labview project DLL. It will call the DLL successfully if it points its record source (the directory where the DLL was built. However if the DLL is copied to the clients working directory and the appellant TestStand step points to the copied DLL, the problem occurs. The TestStand calls the DLL from the working directory of the client, but does not execute the DLL, simply set the status of the step to "Done" where he clearly didn't.

    The vi named in the DLL has correctly, all handles error clusters such that if there is an error in the vi running, the error would be forwarded to TestStand.

    Any ideas please?

    Update: the original problem was never solved, but another method was used successfully to generate an Excel results worksheet. This used controls Active-X to open a file, import a model, write the data, close the file, and then make the new file read-only. It now everything works fine.

  • File not found when you try to call a dll on LabVIEW Real Time machine

    I have a dll called "DLLRTTEST" that I wrote, and claim successfully on my host.  Now, I try to call this dll from a vi that is on my computer in real time.  Currently, I get a message 'error 7 occurred at the crux of library DLLRTTEST.vi. call function' when running

    In the attached screenshot, I try to ensure that the vi that I am running is indeed on the system in real time.  I then use a 'check if file or folder Exists.vi' to confirm that the dll that I'm about to call exists on the system in real time as well.  However, I always get an error "error 7 file not found" from the node call library feature.

    Any help is appreciated.

    Thanks again for all the responses.  As I said earlier, I had already met and solved the problem identified in the link provided by Nathand.  I had to go down to Visual Studio 2008 to go beyond this particular error, after which the app of auditor of the dll in real-time reported my dll needs to run successfully.

    I just got the phone with Jack in charge NEITHER well, and it turns out that I simply had to compile my dll in release mode.  Decommissioning of VS 2008 I got the correct version of dll (msvcr90.dll), but since I am compiling in debug mode, I found myself using msvcr90d.dll (d for debug) who doesn't have my computer in real time.

  • LabVIEW DLL called from C

    I would like to create a DLL in LabVIEW which can be called from a C program.

    The purpose of the DLL is to display a dialog box along side a C program user interface and view a picture is updated continuously in the program.

    The LabVIEW DLL would be

    1 would be considered to be a dialog box that opens up along the side of the user interface of the C program.

    2. the DLL would regularly be called with the parameters passed by the C program.

    3. the dialog box would contains a picture that is updated by the parameters of the permanence of program C.

    Is this feasible?  I assume that the DLL has to work like a demon, because the DLL is a dialog that must cover along the side of the user interface of C.  To run a DLL written in LabVIEW, is the needs of PC - the runtime?

    Everything was OK until 5. For 6, you do not get a reference to something C. You simply call the exported function that is the VI 'set params.

    I have included a sample project to give you an idea. The code LabVIEW is written in LV 8.2 and the project with a version of a DLL specification. I used c# for this example, but you can easily translate it c If you wish.

  • Using a C DLL with complex numbers of Labview

    Hello

    So I would try to use the existing C99 to perform calculations, and for the functions code, the code accepts and returns type numbers 'double complex.   I have spent half a day to find out the hard way that Visual Studio does not complex.h header, so before you spend more time trying to compile a DLL, not done Labview even allows you to send and receive complex of a DLL call numbers?

    When I open the node to call a library function and go to settings, the closest return type I see is double 8 bytes, but nothing about the complex... so...   I am not even convinced that this will work... did anyone done this before?

    Thank you

    Yes, you can use complex numbers. See the example with properly called LabVIEW "" call DLL". There is an example here that deals with complex numbers. You may need to write a wrapper DLL, if.

  • Call a dll via webutil works with Jinitator, but not with the Sun JRE

    Friends,

    I'm trying to call a DLL for Oracle forms using webutil.

    The example I use is from thread WEBUTIL_C_API demo form .

    I followed all the instructions and when I use Jinitiator 1.3.1.28 as the JRE client, then this market. However, when I use Sun JRE 1.5 (1.5.0.19) or Sun 1.6 (1.6.0.14) it does not work and I see the following errors in the java console:
    ERROR>WUL-928 [CApiFunctions.set_invokeoncespec()] Library apiwrap.dll not accessible, or does not contain function eaFindWindow
    ERROR>WUL-910 [CApiFunctions.invokeCApi()] Invoking the function failed: java.lang.NullPointerException
    It appears the problem with the version of Java? Is there something special I need to do to call a dll using the latest versions of the JRE?

    Any help would be appreciated!

    These webutil errors mean that the .dll file is not found in the JRE/bin directory... you have to force webutil to re - load the .dll file into this folder by deleting the webutil.properties file, and then try to run after it again and it should work.

    This properties file are located in either the user/home directory or in the home folder of the JRE.

    i.e.
    C:\Program Files\Java\jre1.5.0_15\webutil.properties

    This file will contain the .dll files that are downloaded to the client... such as configured in the webutil.cfg file.

    Properties of #WebUtil file
    #Mon Aug 10 10:52:10 MDT 2009
    syslib.ffisamp.dll = 1.0
    syslib.d2kwut60.dll = 1.0
    syslib. JNIsharedstubs.dll = 1.0
    syslib. Jacob.dll = 1.0
    syslib.apiwrap.dll = 1.0

  • do not call the dll of Labview in CVI

    I have a Labview dll should call for the CVI. but it always shows error.

    void __cdecl Idx_RW_Reg (uint16_t registry, int32_t RegLength,
    [LVBoolean Data_in], uint8_t OperationRd1Wr0, TD1Hdl * read_reg_table_in,.
    uint16_t PortAddress, TD1Hdl * Table_of_reg_out, LVBoolean ControlFrame [],.
    uint16_t * PortAddressOut, int32_t len2, int32_t len);

    TD1Hdl * read_reg_table_in: what is it, who can tell me

    typedef struct {}
    int32_t dimSizes [2];
    LVBoolean Boolean [1];
    } TD1;
    typedef TD1 * TD1Hdl;

    Any help is greatly appreciated.

    Thank you.

    Hello

    What is your calling code?

    I suggest you read: call a LabVIEW DLL in a CVI or other C/C++ project

    Kind regards

  • My laptop with vista os guard gel and I find it is the problem of "hpqddsvc.dll", how can I solve this problem?

    My laptop screen freeze meet often enough these days problem
    After that I ran safe mode and found the problem of "hpqddsvc.dll?
    How to fix? Thank you!

    Hello

    your problem is with the HP software

    read what it is

    http://www.file.NET/process/hpqddsvc.dll.html

    Try HP support forums

    http://h30434.www3.HP.com/

  • Problem with call on Skype with Lolipop 5.1.1

    When I call on Skype with set helmet, have problem with my microphone, when I turned off and got into this mess, he... Have this problem, anyone? How can I say team xperia to fix?

    @ljubomir993

    This isn't a matter of Sony, it's a matter of Skype, which means you will need to contact the developers of Skype in this regard.

Maybe you are looking for

  • Office Pro 8610: auto reply will not work

    Help, please. Ive read all the possible solutions on this post about auto answer does not, have to press on accept in order to receive faxes. I tried everything, check the fax line, changing all the distinctive rings, stop and disconnect all then res

  • Formate

    Hi guys. I have a laptop G62-a25SI, this laptop has been formatted by mistake and I lost all my and recovery can I get help on that. Fr. Lalla

  • Update error 80070057

    I tried the upgrade to windows 7 Home premium to windows 10. He let me pass because the error code 80070057.

  • BlackBerry Smartphones BB 9900 battery

    I was disappointed by my battery with the 9900 BB new life. Read posts on possible corrections, but nothing helped. Started tinkering and found my backlight setting was too high - 70. Lowered to 10 and what a difference it made. Go about 9 hours and

  • Error opening connection JDBC of Weblogic server 10.3.5

    I developed an ADF application in Jdeveloper11.1.1.7 and it deployed in Weblogic server 10.3.5. Jdeveloper every thing works perfectly but WebLogic server I see the error in the server stack (error when opening JDBC connection, Caused by password nul