difference between a console app and a win forms app

J

Jeremy

I have a small block of code that uses DllImport tags to call methods in a
dll written in C. I'm not sure how the dll works internally, but when I
call some of these methods from a windows console application I get an
error, but when I call them from a windows forms application I don't get the
error.


Also, when I'm debugging through visual studio, the console application
works, but not when I run it from the command line. Strange?
 
J

Jeremy

Also, I noticed that If I call these dll methods in the windows app, from a
button click on a form it works but if I call the dll methods from the forms
load event, when the form is the one passed to the Application.Run method in
the apps main() function I get the error. The only thing I can think of is
that by the time the button click happens, the application process is "fully
constructed" but when my dll method call is made from the main() function,
something under the hood in the application process isn't constructed yet.
But I need to make this call from a console application. Any body have any
ideas how to get this to work?

Works in win forms example:
private void bnTestButton_Click(object sender, System.EventArgs e)
{
DLLCall();
}

Does not work in win forms example:
[STAThread]
static void Main(string[] args)
{
Application.Run(new frmTest());
}

private void frmTest_Load(object sender, System.EventArgs e)
{
DLLCall();
}

Does not work in console example:

[STAThread]
static void Main(string[] args)
{
DLLCall();
}
 
J

John Saunders [MVP]

Jeremy said:
I have a small block of code that uses DllImport tags to call methods in a
dll written in C. I'm not sure how the dll works internally, but when I
call some of these methods from a windows console application I get an
error

Ok, so, which error is it? Please post the entire exception (which is what I
presume you meant by "error").
 
L

Leon Lambert

I am not sure of what your particular problem is but i have seen a
similar one in the past. My problem was the DLL either was or used a COM
component. It seemed that when used with .Net console the COM layer
wasn't initialized properly or didn't have a message pump. Mine also
worked fine if i called it from Windows application. I ended up having
to make a C# COM interface assembly to wrap the C dll. The C# COM
assemble magically setup everything it took to make the C COM DLL happy.

Hope this helps.
Leon Lambert
 
J

Jeremy

The error is "the remote workstation has not initialized the mrwscript.dll"
It's not a .net exception as it's being generated from within the dll.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top