473,386 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

difference between a console app and a win forms app

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?
Sep 27 '07 #1
4 2843
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();
}
"Jeremy" <no****@please.comwrote in message
news:%2******************@TK2MSFTNGP02.phx.gbl...
>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?

Sep 27 '07 #2
"Jeremy" <no****@please.comwrote in message
news:%2******************@TK2MSFTNGP02.phx.gbl...
>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").
--
--------------------------------------------------------------------------------
John Saunders | MVP - Windows Server System - Connected System Developer

Sep 28 '07 #3
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

Jeremy wrote:
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?

Sep 28 '07 #4
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.

"John Saunders [MVP]" <john.saunders at trizetto.comwrote in message
news:eY**************@TK2MSFTNGP06.phx.gbl...
"Jeremy" <no****@please.comwrote in message
news:%2******************@TK2MSFTNGP02.phx.gbl...
>>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").
--
--------------------------------------------------------------------------------
John Saunders | MVP - Windows Server System - Connected System Developer

Sep 28 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mullin Yu | last post by:
But, I want is that I can have a Main app that will start a new process or kill one particular or all process. The process will open a console exe. But, I don't want the user to close the console...
1
by: James Carnley | last post by:
I am learning how to use windows forms and I have come across a small problem. Whenever I run my program it opens a console window before launching the windows form. The console doesnt go away...
12
by: z. f. | last post by:
what's the difference between using the VB.NET function IIF or the c# operator ? VB.NET: a = iif ( b=c, d, e) C#: a= (b==c)?d:e TIA, z.
12
by: Jarod_24 | last post by:
I got a project called "Forms" that hold some forms and stuff in my solution. A argument at startup defines wether to use a From or Console. My plan was to create a myConsole class that would...
8
by: Alison | last post by:
Hi, Al I am trying to design a user interface which provides both menus and toolbars for some users to click on whatever they want to do, at the same time, I would like to have a console window...
4
by: Hugh O | last post by:
Hi, My question may be very elementary to everyone else but not to me. I have substantial VB experience but absolutely no VS.Net experience. I have an Access application with a lot of VB code...
11
by: chopsnsauce | last post by:
Here's the example: Dim frm As New FORM1 Try frm.show Catch ex As Exception msgbox ex.message
12
by: Dilip | last post by:
Hi All I have a server based C# console application. This application must hide its console window when its launched out on the field. So I dutifully P/Invoke'd FindWindow/ShowWindow...
3
by: Author | last post by:
I have always been wondering if there is any significant different between doing System.Console.WriteLine("Employee Name = " + employee.FirstName + " " + employee.LastName); and ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.