Re: Exporting Managed code as Unmanaged

Thomas Heller <[email protected]> Wed, 17 Dec 2003 08:57:46 +0100
Newsgroups gmane.comp.python.ctypes.devel
Message-ID <[email protected]>
Thomas Heller <[email protected]> writes:

> Mulot Gérard <[email protected]> writes:
>
>> Exporting Managed code as Unmanaged  :
>> http://www.csharphelp.com/archives3/archive500.html
>>
>> the following c# code is exported as an unmanaged dll with ILDASM from Net
>> Framework SDK
>>
>> // HelloWorldDll.cs
>> using System;
>>
>> namespace HelloWorldDll
>> {
>> public class HelloWorldClass
>> {
>> public static string SayHello(string name)
>> {
>> return ("Hello " + name);
>> }
>> }
>> }
>>>>> from ctypes import *
>>>>> x = windll.HelloWorldDll
>>>>> x.SayHello('Gerard')
>> 1465528
>>>>>
>>
>> I can't return the string Hello Gerard
>
Ok, I've downloaded and extracted the dll from the rar file in the above
url, and - no problems here (except that winzip doesn't handle rar
files):

>>> from ctypes import *
>>> windll.HelloWorldDll
<WinDLL 'HelloWorldDll', handle 860000 at 982800>
>>> windll.HelloWorldDll.SayHello
<ctypes._StdcallFuncPtr object at 0x009248C8>
>>> windll.HelloWorldDll.SayHello()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: Procedure probably called with not enough arguments (4 bytes missing)
>>> windll.HelloWorldDll.SayHello("Thomas")
1547976
>>> windll.HelloWorldDll.SayHello.restype = c_char_p
>>> windll.HelloWorldDll.SayHello("Thomas")
'Hello Thomas'
>>> ^Z

Thomas

PS: I noticed you used the ctypes-devel list for this msg, ctypes-users
would be the 'correct' list to use ;-).



-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click