difference between a console app and a win forms app

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeremy

    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?


  • Jeremy

    #2
    Re: difference between a console app and a win forms app

    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_Cl ick(object sender, System.EventArg s e)
    {
    DLLCall();
    }

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

    private void frmTest_Load(ob ject sender, System.EventArg s e)
    {
    DLLCall();
    }

    Does not work in console example:

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


    "Jeremy" <nospam@please. comwrote in message
    news:%23%23CmBQ TAIHA.4568@TK2M SFTNGP02.phx.gb l...
    >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?
    >

    Comment

    • John Saunders [MVP]

      #3
      Re: difference between a console app and a win forms app

      "Jeremy" <nospam@please. comwrote in message
      news:%23%23CmBQ TAIHA.4568@TK2M SFTNGP02.phx.gb l...
      >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

      Comment

      • Leon Lambert

        #4
        Re: difference between a console app and a win forms app

        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?
        >
        >

        Comment

        • Jeremy

          #5
          Re: difference between a console app and a win forms app

          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.saunder s at trizetto.comwro te in message
          news:eYnqoJYAIH A.4984@TK2MSFTN GP06.phx.gbl...
          "Jeremy" <nospam@please. comwrote in message
          news:%23%23CmBQ TAIHA.4568@TK2M SFTNGP02.phx.gb l...
          >>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
          >

          Comment

          Working...