Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 2nd, 2008, 2:28 PM   #1
JD-Salinger
Unknown
 
JD-Salinger's Avatar
 
Join Date: Apr 2008
Location: unknown
Posts: 87
Rep Power: 1 JD-Salinger is on a distinguished road
calling native functions

i have to call a native function in c++, the puts(), i compiled the program but it doesnt output the string parameter?
but just pure blank

c# Syntax (Toggle Plain Text)
  1. using System;
  2. using System.Runtime.InteropServices;
  3.  
  4. class PlatformInvokeTest
  5. {
  6. [method: DllImport("msvcrt.dll")]
  7. static extern string puts(string x);
  8. static void Main()
  9. {
  10.  
  11. puts("Hello World!");
  12. Console.ReadKey();
  13.  
  14. }
  15. }
__________________
-------------------------------------------------------------------------
I thought what I'd Do was, I'd pretend to be one of those deaf mutes
------------------------------------------------------------------------
JD-Salinger is offline   Reply With Quote
Old Aug 2nd, 2008, 3:13 PM   #2
sarehu
Newbie
 
Join Date: Aug 2008
Posts: 5
Rep Power: 0 sarehu is on a distinguished road
Re: calling native functions

Try calling the native C code, fflush(stdout). It could be that the C standard library's output stream is not getting flushed, because Console.ReadKey() doesn't care or know about that. If you asked for input using a standard C stdin function, i.i.r.c. it would flush the stdout stream automatically. The C# standard input functions probably flush the C# standard output buffer, and don't know anything about the C output buffer, which means you have to flush it manually.

Maybe. Anyway, try it.
sarehu is offline   Reply With Quote
Old Aug 2nd, 2008, 7:12 PM   #3
lectricpharaoh
SEXY SHOELESS GOD OF WAR!
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,197
Rep Power: 5 lectricpharaoh will become famous soon enough
Re: calling native functions

Your code works fine for me exactly as is. But yeah, try flushing stdout, to ensure it actually writes any buffered output.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Aug 2nd, 2008, 10:43 PM   #4
JD-Salinger
Unknown
 
JD-Salinger's Avatar
 
Join Date: Apr 2008
Location: unknown
Posts: 87
Rep Power: 1 JD-Salinger is on a distinguished road
Re: calling native functions

thank you thank you thank you!!!
__________________
-------------------------------------------------------------------------
I thought what I'd Do was, I'd pretend to be one of those deaf mutes
------------------------------------------------------------------------
JD-Salinger is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling exit(???) functions BstrucT C 12 Jan 11th, 2008 3:16 AM
Calling .net functions from C++ uman C++ 2 Jul 26th, 2006 5:36 PM
binding between ordinary member functions & polymorphic member functions ASH C++ 2 May 11th, 2006 5:36 AM
Exporting Functions victorsk Visual Basic 1 May 18th, 2005 3:32 PM
User-defined creatNode and deleteNode functions for a doubly-linked list jgs C 2 Apr 28th, 2005 9:53 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:44 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC