LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

passing string to dll

Hello,
I am trying to pass a string into a little wrapper dll for the win32 function InitiateSystemShutdownEx.  It is not working...it always generates exceptions.  I have tried removing the string inputs and using hard coded strings in the dll, and that works fine.
 
Anyway, I have attached my vi and c code (btw, I'm new at writing dlls so there could very well be a simple mistake in there).  I'm also using the free OpenWatcom compiler - maybe that's a problem?
 
Any help you could give would be greatly appreciated.  Thanks,
 
Jon
 
PS. I saw some very similar posts, but none of them had a concrete resolution.
 
Download All
0 Kudos
Message 1 of 9
(4,592 Views)
Try converting your strings into a byte array (String to Byte Array function), and declaring your CStr to byte arrays in your DLL.  In C, strings are character arrays and must be terminated with a NULL character (ASCII code = 0).  This causes some problems between LV and C.  It is best to use byte arrays and convert as needed.
You could try just concatening a NULL character after the string before you send it to the DLL.  This would be easier to try first.
 

Message Edited by tbob on 02-15-2006 04:40 PM

- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 9
(4,592 Views)
Thanks for the response, tbob.
 
I must be doing something fundamentally wrong...
 
I deleted the strings from the dll and decided to just pass in the other parameters, but they don't seem to work either.  I don't get the memory exception and the LV code executes without complaining, but the dll doesn't interpret the parameters I pass correctly.
 
For example, when run, the dll should display a message box for dwTimeout seconds, but it is always instant, no matter what number I wire to the terminal.
 
If I write a little C program to call the dll though, it works correctly...I'm so confused!
 
Anyway, if anyone could set me straight, I would appreciate it.
 
Thanks,
Jon
0 Kudos
Message 3 of 9
(4,568 Views)

Ok, this is really starting to screw with my head.

I made a really simple dll:

#include "lvdll.h"

__declspec(dllexport) int AddInts(int x, int y) {
    int z;
    z = x+y;
    return(z);
}

 

A little test app shows this works correctly.  However, in LabVIEW, I always get 1244517 as the result.  I'm passing the numbers in as i32 and using C calling conventions.

 

Anyone have an idea?

 

Thanks,

Jon

0 Kudos
Message 4 of 9
(4,565 Views)

Hi tbob

Something completelly not relevant to the thread.

I just wanted to know how did you linked the picture to the post, so it displays in the browser?

take care

Pawel

 

0 Kudos
Message 5 of 9
(4,558 Views)

Bigg_jon:  Another thing to try is to change the calling convention.  There are two choices, Standard (WIN API) and C.  These are chosen in the screen that appears when you double click on the Call Library function icon.  Whichever you have selected, try selecting the other.  This may solve your problem.  I would think that the C calling convention should work, but I've seen instances where Win API works better even with DLLs produce in C.  I all depends on how the DLL was built.  I would like someone to explain in detail the differences between the two.  I suspect it has something to do with declarations in the C code.

 

Pawel:  Neat trick, I had to ask someone to learn this one too.  First create your vi.  Then highlite the part of the block diagram you want to post.  Copy to clipboard.  Open MS Paint.  Paste.  Resize if you have to.  Save the paint file as a PNG file.  Add the png file as an attachment to your post in the usual way like you would attach a vi.  Click Submit Post.  As soon after you see the post, on the right side is a drop down menu called Options.  Click and select Edit Message.  You only have a limited amount of time to do this so be quick (I think it is a couple of minutes).  Your post comes back in edit mode.  Click on the attachment.  Copy the HTML address of the attachment (highlite and press CTRL-C).  Click the Back button on your browser.  Place the cursor after your text in the Message Body edit box.  Click the Insert an Image button (small yellow box with mountains in it).  Paste the copied HTML address in the pop up box and click OK.  You should see the image on your post.  Click Submit Post.  You will also see added text "Message Edited by ..." or something like that at the end of your post.  You can edit your post anytime within the couple of minutes range using the Options menu.  Lets say you see a mistake, or someone beat you to an answer.  Edit your post and re-submit.  Lots of steps but it is quite easy to do.

Message Edited by tbob on 02-16-2006 10:20 AM

- tbob

Inventor of the WORM Global
Message 6 of 9
(4,557 Views)

Thanks a lot tbob

It works! Robot Happy

And apparently it does not need to be a png, but any graphical file accepted by browser.

Thanks.

take care

Pawel

Message Edited by pawel on 02-16-2006 11:35 AM

Message Edited by pawel on 02-16-2006 11:36 AM

Message Edited by pawel on 02-16-2006 11:37 AM

Message Edited by pawel on 02-16-2006 11:37 AM

Message Edited by pawel on 02-16-2006 11:38 AM

Download All
0 Kudos
Message 7 of 9
(4,557 Views)
Pawel, yes it can be any graphical file.  However, stay away from bitmaps (.bmp) because they are quite large in size.  I guess PNG is the most commonly used format.  Of course GIF is great for animation.
- tbob

Inventor of the WORM Global
0 Kudos
Message 8 of 9
(4,533 Views)
Did you take a look at the example that comes with LabVIEW? There's a pretty big one that covers all sorts of datatypes. Look in the "examples\dll\data passing" in your LabVIEW install directory.
0 Kudos
Message 9 of 9
(4,522 Views)