Go Back   RunUO - Ultima Online Emulation > Developer's Corner > Programming > C#

C# C# Discussion

Reply
 
Thread Tools Display Modes
Old 07-24-2007, 10:44 PM   #1 (permalink)
Master of the Internet
 
TMSTKSBK's Avatar
 
Join Date: Feb 2004
Location: NC/NC State Univ
Age: 23
Posts: 16,424
Default C# -> C

Oh joy.

@ work, they want me to make a program that jumps on rasapi32.dll (unmanaged C code), and dials numbers.

rasapi is the thing that makes dial-up networking work. Same as rasdial.

So, if any of you can give me pointers on how to work with unmanaged stuff (ya, P/Invoke & COM stuff...but...meh) that'd be great.

Sorry for the vagueness. Very tired.
__________________
Goodbye, folks.
TMSTKSBK is offline   Reply With Quote
Old 07-24-2007, 11:49 PM   #2 (permalink)
Forum Expert
 
TheOutkastDev's Avatar
 
Join Date: Sep 2002
Location: Houston, Texas
Age: 22
Posts: 3,933
Default

pinvoke.net: RasDial (rasapi32)
TheOutkastDev is offline   Reply With Quote
Old 07-25-2007, 12:45 AM   #3 (permalink)
Master of the Internet
 
TMSTKSBK's Avatar
 
Join Date: Feb 2004
Location: NC/NC State Univ
Age: 23
Posts: 16,424
Default

Yeah, I read that fun little blurb. Already using significant portions (all) of it. (Thanks, though.)

How does one do a callback from C to C#? I understand delegates in C# well enough to do one, but I've never tried to make unmanaged code that I can't touch call managed code...

So yeah. My extra-kludgy workaround is to grab rasdial.exe and throw command line args at it. Not terribly happy with that..
__________________
Goodbye, folks.

Last edited by TMSTKSBK; 07-25-2007 at 12:47 AM.
TMSTKSBK is offline   Reply With Quote
Old 07-25-2007, 10:56 AM   #4 (permalink)
ConnectUO Creator
 
Jeff's Avatar
 
Join Date: Jan 2004
Age: 27
Posts: 4,825
Default

Quote:
Originally Posted by TMSTKSBK View Post
Yeah, I read that fun little blurb. Already using significant portions (all) of it. (Thanks, though.)

How does one do a callback from C to C#? I understand delegates in C# well enough to do one, but I've never tried to make unmanaged code that I can't touch call managed code...

So yeah. My extra-kludgy workaround is to grab rasdial.exe and throw command line args at it. Not terribly happy with that..
A callback from C to C# is done exactly the same way. You just have to create the callback in C#

Heres a greate example.

pinvoke.net: CopyFileEx (kernel32)

CopyFileEx requires a callback, as it is an asynchronis method.

Basically, find out all the arguments the callback needs, create the delegate for it using these arguments and feed it to the invoked method. Pretty much works the exact same way it works creating a callback C#->C# .

On Microsofts page about this function found here they describe the delegate as such

Quote:
Originally Posted by msdn
lpvNotifier
[in] Specifies a window handle or a RasDialFunc, RasDialFunc1, or RasDialFunc2 callback function to receive RasDial event notifications. The dwNotifierType parameter specifies the nature of lpvNotifier. Please refer to its description preceding for further detail.

If this parameter is not NULL, RasDial sends the window a message, or calls the callback function, for each RasDial event. Additionally, the RasDial call operates asynchronously: RasDial returns immediately, before the connection is established, and communicates its progress via the window or callback function.

If lpvNotifier is NULL, the RasDial call operates synchronously: RasDial does not return until the connection attempt has completed successfully or failed.

If lpvNotifier is not NULL, notifications to the window or callback function can occur at any time after the initial call to RasDial. Notifications end when one of the following events occurs:

* The connection is established. In other words, the RAS connection state is RASCS_Connected.
* The connection fails. In other words, dwError is nonzero.
* RasHangUp is called on the connection.

The callback notifications are made in the context of a thread captured during the initial call to RasDial.
Note specifically this line

Quote:
Originally Posted by msdn
[in] Specifies a window handle or a RasDialFunc, RasDialFunc1, or RasDialFunc2 callback function
These functions are outlined in the link above but here are links to all three

http://msdn2.microsoft.com/en-us/library/aa377039.aspx
RasDialFunc1 (Windows)
RasDialFunc2 (Windows)

I would assume you can just create delegates that manage this, Or and this may be your better bet, just create a wrapper to invoke these.
__________________
Jeff Boulanger
ConnectUO - Core Developer

Want to help make ConnectUO better? Click here to submit your ideas/requests
Use your talent to compete against other community members in RunUO hosted coding competitions

If you know XNA (even if its just a little) or are a good artist(2d or 3d) and are interested in making games for a hobby send me a pm or drop by #xna in irc.runuo.com. I'm looking to put together a small game development team.


Please do not pm me for support. If you are having issues please post in the appropriate forum. Thanks for your continued support of both ConnectUO and RunUO

Last edited by Jeff; 07-25-2007 at 11:10 AM.
Jeff is offline   Reply With Quote
Old 07-25-2007, 10:40 PM   #5 (permalink)
Master of the Internet
 
TMSTKSBK's Avatar
 
Join Date: Feb 2004
Location: NC/NC State Univ
Age: 23
Posts: 16,424
Default

Thanks, Jeff.

Give me a day or so to digest that...
__________________
Goodbye, folks.
TMSTKSBK is offline   Reply With Quote
Old 07-26-2007, 01:41 AM   #6 (permalink)
ConnectUO Creator
 
Jeff's Avatar
 
Join Date: Jan 2004
Age: 27
Posts: 4,825
Default

Quote:
Originally Posted by TMSTKSBK View Post
Thanks, Jeff.

Give me a day or so to digest that...
Your really thinking about it to hard I think. Just use a delegate the same as you would as always in C#, or just use any of those 3 functions the same as you are using the RasDial function.
__________________
Jeff Boulanger
ConnectUO - Core Developer

Want to help make ConnectUO better? Click here to submit your ideas/requests
Use your talent to compete against other community members in RunUO hosted coding competitions

If you know XNA (even if its just a little) or are a good artist(2d or 3d) and are interested in making games for a hobby send me a pm or drop by #xna in irc.runuo.com. I'm looking to put together a small game development team.


Please do not pm me for support. If you are having issues please post in the appropriate forum. Thanks for your continued support of both ConnectUO and RunUO
Jeff is offline   Reply With Quote
Old 07-31-2007, 10:37 PM   #7 (permalink)
Master of the Internet
 
TMSTKSBK's Avatar
 
Join Date: Feb 2004
Location: NC/NC State Univ
Age: 23
Posts: 16,424
Default

Just an FYI...got it working. Yay.

Now if only they gave me some time to actually work on this...
__________________
Goodbye, folks.
TMSTKSBK is offline   Reply With Quote
Reply

Bookmarks


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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5