none
Dll Import problem RRS feed

  • Question

  • I was trying to implement the PInvoke tutorial given on MSDN website.

    It had some code like this.

    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();
        }
    }
    But The problem is that on my console screen I am not getting any output. Neither my compiler is 
    generating any errors. Can anyone tell me what the problem is?
    

    Thanks and Regards Mahesh Murty Senior Fellow ilabs The Robotics and Embedded Systems Research Lab Nagpur India
    • Moved by Leo Liu - MSFT Monday, October 3, 2011 7:16 AM Moved for better support. (From:Visual C# Language)
    Saturday, October 1, 2011 10:39 AM

Answers

  • I tried your sample, and see the same thing you do, though I did have to add CallingConvention=CallingConventeion.Cdecl to avoid a runtime error..  This thread/discussion may explain why this is happening.  I cannot find an updated version of this example other than the one on msdn, which says that it is for VS 2003.
     

    --
    Mike
    • Marked as answer by Paul Zhou Monday, October 10, 2011 7:32 AM
    Saturday, October 1, 2011 12:20 PM
  • Hi,

    Difference between pressing F5 and Ctrl-F5, you can refer to:F5 vs. Ctrl-F5

     


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Paul Zhou Monday, October 10, 2011 7:32 AM
    Wednesday, October 5, 2011 7:27 AM

All replies

  • I tried your sample, and see the same thing you do, though I did have to add CallingConvention=CallingConventeion.Cdecl to avoid a runtime error..  This thread/discussion may explain why this is happening.  I cannot find an updated version of this example other than the one on msdn, which says that it is for VS 2003.
     

    --
    Mike
    • Marked as answer by Paul Zhou Monday, October 10, 2011 7:32 AM
    Saturday, October 1, 2011 12:20 PM
  • please read more about DllImportAttribute class to know more about function importing options!
    Any fool can know. The point is to understand.(Albert Einstein)
    Sunday, October 2, 2011 8:31 AM
  • Thanks Mike. I was able to compile the code without debugging but I was unable to understand what happened when I pressed simply F5 and when I press CTRL + F5.

    But I was able to compile my code and see the output. I would be thankful if you explain me the reason.


    Thanks and Regards Mahesh Murty Senior Fellow ilabs The Robotics and Embedded Systems Research Lab Nagpur India
    Monday, October 3, 2011 4:15 PM
  • Hi,

    Difference between pressing F5 and Ctrl-F5, you can refer to:F5 vs. Ctrl-F5

     


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Paul Zhou Monday, October 10, 2011 7:32 AM
    Wednesday, October 5, 2011 7:27 AM
  • i suggest you to import not implemented APIs in .NET Framework. for Console operations,  you can use Console Class.

     


    Any fool can know. The point is to understand.(Albert Einstein)
    Wednesday, October 5, 2011 8:59 AM