Click to See Complete Forum and Search --> : prodding the unmanaged dll


ikirwan
November 6th, 2003, 10:32 AM
Hi,

I read the following article on P/Invoke which I found very informative:
http://msdn.microsoft.com/msdnmag/issues/03/07/net/

I am trying to tie up a C# GUI to a dll created by Matlab/Simulink from Mathworks. This is a real time model which is converted in C then compiled to a dll. It has a number of function calls for initialising the model, updating and so on. It also and contains global variables for accessing the I/O of the model (not ideal but that's how they chose to do it).

I am no Windows programming expert, in fact you could say am a novice. So here is my problem. I tried working from the example code in figure 1 of the article. My dll is called model_sfun.dll which I have placed in the project directory of the c# GUI along with the .cs files and resources etc. so I used the line:
[DllImport("model_sfun.dll")] // I omitted the text ", setLastError=true" (as used in the example) because it caused me an error
static extern void modelUpdate();// an imported function

then subsequently call the declared function via a wrapper function which I also created within the class, from an event handler triggered from a timer. (This may well be more information that you need to answer the question).

When I start the debugger the app generates a System.DllNotFoundException

I have also tried placing the dll in the system and system32 directories, but get the same exception. Additionally I tried to add a reference to the dll in to the project, but the project will not accept the dll, complaining that it is not a valid assembly or COM object.

Can anyone help?

Cheers
Ian