Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. pinovoke program runs but has no output

pinovoke program runs but has no output

Scheduled Pinned Locked Moved C#
csharpvisual-studiocomhelptutorial
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sharp_k
    wrote on last edited by
    #1

    I followed a simple tutorial from microsoft to use a simple function puts in msrcrtdll.dll. I created a console application (C#) and copied the code as it is given. The program runs fine but dees not print as it is supposed to do. I am using VS2008. Please help. Here is the code // PInvokeTest.cs using System; using System.Runtime.InteropServices; class PlatformInvokeTest { [DllImport("msvcrt.dll")] public static extern int puts(string c); [DllImport("msvcrt.dll")] internal static extern int _flushall(); public static void Main() { puts("Test"); _flushall(); } } http://msdn.microsoft.com/en-us/library/aa288468(VS.71).aspx#pinvoke_example1[^]

    M 1 Reply Last reply
    0
    • S sharp_k

      I followed a simple tutorial from microsoft to use a simple function puts in msrcrtdll.dll. I created a console application (C#) and copied the code as it is given. The program runs fine but dees not print as it is supposed to do. I am using VS2008. Please help. Here is the code // PInvokeTest.cs using System; using System.Runtime.InteropServices; class PlatformInvokeTest { [DllImport("msvcrt.dll")] public static extern int puts(string c); [DllImport("msvcrt.dll")] internal static extern int _flushall(); public static void Main() { puts("Test"); _flushall(); } } http://msdn.microsoft.com/en-us/library/aa288468(VS.71).aspx#pinvoke_example1[^]

      M Offline
      M Offline
      martin_hughes
      wrote on last edited by
      #2

      Stick a Console.Read() after the call to _flushall(); and then run the exe directly from the debug or bin folder. Not sure why it doesn't appear in the VS console window, though - possibly because it isn't the stdout target?

      modified on Monday, May 12, 2008 1:31 PM

      S 1 Reply Last reply
      0
      • M martin_hughes

        Stick a Console.Read() after the call to _flushall(); and then run the exe directly from the debug or bin folder. Not sure why it doesn't appear in the VS console window, though - possibly because it isn't the stdout target?

        modified on Monday, May 12, 2008 1:31 PM

        S Offline
        S Offline
        sharp_k
        wrote on last edited by
        #3

        Thank you so much. It worked by directly running the .exe file. Also i created a simple DLL which implements a sum function. When i implement it in C#, it says it can not load the dll. I copied the DLL to the current folder. I do not know why it is not loading the DLL. Do you know why? Thanks again

        M M 2 Replies Last reply
        0
        • S sharp_k

          Thank you so much. It worked by directly running the .exe file. Also i created a simple DLL which implements a sum function. When i implement it in C#, it says it can not load the dll. I copied the DLL to the current folder. I do not know why it is not loading the DLL. Do you know why? Thanks again

          M Offline
          M Offline
          martin_hughes
          wrote on last edited by
          #4

          I'm sorry, I don't - if the usual rules of dll's is being followed it would need to be in the release/debug folder or in the System directory, but this goes beyond my experience with P/Invoke.

          S 1 Reply Last reply
          0
          • S sharp_k

            Thank you so much. It worked by directly running the .exe file. Also i created a simple DLL which implements a sum function. When i implement it in C#, it says it can not load the dll. I copied the DLL to the current folder. I do not know why it is not loading the DLL. Do you know why? Thanks again

            M Offline
            M Offline
            Mike Dimmick
            wrote on last edited by
            #5

            If you wrote it in C++, the name of the function as seen by other tools will have been 'decorated' (some people say 'mangled') with extra characters indicating the types of the parameters. This is to support overloading, that is, multiple functions with the same name. To suppress name mangling for a function, put extern "C" before the function declaration.

            DoEvents: Generating unexpected recursion since 1991

            1 Reply Last reply
            0
            • M martin_hughes

              I'm sorry, I don't - if the usual rules of dll's is being followed it would need to be in the release/debug folder or in the System directory, but this goes beyond my experience with P/Invoke.

              S Offline
              S Offline
              sharp_k
              wrote on last edited by
              #6

              The problem was with my 64 bit windows (Vista). I have a couple of issue with it and this is one of them. The code runs fine on another machine (32 bit vista). Thanks for the help though.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups