I am controlling the com port with calling a dll(dwdio.dll--see the attachment). The VI I used is also attached below. I just used four functions of this dwdio.dll, as followings: 1. bool DWD_set_comport(unsigned char com_port,int *handle) Parameter config:return type--unsigned 8-bit int(value),com_port --unsigned 8-bit int(value),handle--signed 32-bit int(point to value)
Yaoming, I am curious as to whether the code in the dll is declared as external. I was experiencing the same problem when calling a C++ dll and it was solved by using 'extern' in my code and then building that code into the dll. However if this is not your code that you can alter and rebuild then this suggestion wont help you. I just figured I would mention it as it took me a while to find and solved the same problem you are experiencing. Best of luck. -Dave
NIDave, Thanks for your reply.I can't do what you said using "extern" in the dll source code,because just like you said that is not my code and I can't alter anything.
To make my problem clearer, I would like to share more information on it: 1. I heard that the dll is compiled by Borland C++ 2. In fact, there is already some LV program using the dwdio.dll and it works well, but I can't get the LV source code. So I think there is no problem to call this dll with LV. 3. Before the LV crash, you can see the following error message "The instruction 0x0c43a394 can't refer to the memory 0x0c43a394, which can't be read."
Could anybody help me? It's really very important and urgent to me. Thanks in advance.
To make things clear, I can upload the source code of my vi, but I am wondering if it can be open without hardware dongle license.
Thanks for your reply. I studied the application note from the super-link you provided. I also studied the other two super-links in that notes. But I don't think that can help me to sort my problem.
Firstly, I paste the three super-links I read as following: 1. LabVIEW Application Error: "The instruction at [address] referenced memory at [some address="address"]. The memory could not be read."(http://digital.ni.com/public.nsf/websearch/E8C5C452F04EF7BE86256EF50068CAAF?OpenDocument) 2. When Using the Call Library Function Node, LabVIEW Crashes after the Function Executes(http://digital.ni.com/public.nsf/websearch/58596F5D41CE8EFB862562AF0074E04C?OpenDocument) 3. LabVIEW Crashes after a VI That Calls a DLL Exits(http://digital.ni.com/public.nsf/3efedde4322fef19862567740067f3cc/91d4656b15b0dc7a86256ace0073ca90?OpenDocument)
You can see my vi that I attached. I never use any string or array, so I don't need to allocate any memory. What parameters I used in my vi are only some integers and interger pointers.
From my understanding, what I suspected most is the "handle" parameter which is a integer pointer data type. Does anybody has such experience on how to deal with pointers correctly?
The first thing you have to make sure is that the return types and data types of arguments for functions in Call Library Function exactly match the data types your function uses. Erroneous data types assignments can cause crashes.
SVences Applications Engineer National Instruments
> SVences,<br><br>I know that Erroneous data types assignments can cause crashes.
> I have checked all the data type with my experience and knowledge,but I didn't
> find anything should cause this crash problem.<br><br>After all,I am not very
> experienced in Call Library Function, so maybe my vi still have some erroneous
> data type assignments. Can any DLL expert help me to locate them?
> For the original function description, I have posted as attachment in the first
> post. Therefore,anybody who want to check my data type error can have a check
> with that function description.
> That issue is very urgent and important to me. Can anybody to help me sort
> this problem as soon as possible? Thanks in advance.
A few remarks:
1) the Bool return value is probably an int. It doesn't look like a
standard Widnows datatype so you will have to look in the documentation.
However this is unlikely to crash your code.
2) The handle parameter for DWD_set_comport should be set as Pass:
Pointer to Value. All other parameters should be passed by Value only as
they are not pointers at all. Also please wire a 0 constant to the right
side of the CLN for that parameter to provide memory for the DLL to
3) The calling convention for the DLL functions is not obvious from your
documentation. You have the choice between C (cdecl) and WINAPI
(stdcall) on Windows. Since this DLL seems to be available for multiple
platforms (The remark for each function) it may be that the developer
decided to use cdecl calling convention (a smart choice I would say) but
Windows DLLs usually use stdcall instead.
Having the wrong one will absolutely crash LabVIEW but usually at the
moment you return from the functioncall and not later on.
So I would guess the most probable cause is number 2, but don't discount
the other ones completely.
For number 1),I am not sure if it is a windows data type or not but I really see "bool<->signed 32-bit int" relation in Labview's example code. You can get this example with searching "dll" in menu "Help/find examples...". So, I agree with you that the return type Bool will crash my code.
For number 2), which you suspected most and so did I, However, I really set the handle as your suggestion. The handle in DWD_set_comport is set as "pass pointer to value" and other Library Nodes are set as "pass value". You also said "wire a 0 constant to the RIGHT side of the CLN for that parameter to provide memory for the DLL to write in", but I think you were saying "the left" but not "the right". For this point, I do have already tried to wire a 0 constant to handle as input parameter in DWD_set_comport, but it seems have no impact on the crashing.
For number 3),I am sure the calling convention should be "C" but not "WINAPI". If you try to use "WINAPI" in my vi the Labview will crash imediately when you run this vi.
Any way, Thank you. Do you have any other suggestions for me to try? The trouble is really so boring,but I don't want to give up. Please help me.
For the dll call example in Labview I mentioned in number 1), I can give out the path for your reference---C:\Program Files\National Instruments\LabVIEW 7.0\examples\dll\data passing\.