pinovoke program runs but has no output
-
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[^] -
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[^]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
-
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
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
-
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
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.
-
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
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
-
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.