[python-win32] Problem on com server ony in a specifie application

Matteo Boscolo matteo.boscolo at boscolini.eu
Sat Jan 8 08:11:17 CET 2011


After a lot of testing I find a solution that solve the problem .
When I call my comInit method I need to accept a return type..

for c# :
object o=obj.GetType().InvokeMember("comInit",

                  BindingFlags.InvokeMethod, null, obj, objArgs);

In This way, and modifying the comInit function to make it return a value,
all works with anycpu 64Bit and 32Bit and thinkdesing :-).

S_OK=1

.
.
.
.
def comInit(self,obj=None):
	self._obj=test1(obj)
	return S_OK
There is a standard return way to use in com server method ?
I try with None but It dose not work.

Thanks in advance,
Matteo


Il 07/01/2011 18:47, Tim Roberts ha scritto:
> Matteo Boscolo wrote:
>> I made the following test:
>> I create a c# application that call the some method
>> //code
>>               object obj = Activator.CreateInstance
>>                   (Type.GetTypeFromProgID("test.Application"));
>>               object[] objArgs = new object[1];
>>               objArgs[0] = "ciao";
>>               obj.GetType().InvokeMember("comInit",
>>                   BindingFlags.InvokeMethod, null, obj, objArgs);
>>
>>               object ret=obj.GetType().InvokeMember("Now",
>>                   BindingFlags.InvokeMethod, null, obj, objArgs);
>>
>> If I compile the code under any cpu I got the some problem that in
>> thinkdesing
>> If I compile the code under 32Bit cpu I have no error and the com server
>> works well ..
>>
>> So now my question is :
>> Can I manage this situation under python code ?
> This suggests that ThinkDesign is actually a 64-bit app.
>
> First, a couple of facts.  A 64-bit application cannot call a 32-bit DLL
> (nor vice versa).  Your Python code is a 32-bit DLL.  .NET applications
> are kind of a strange beast.  You probably know that, when you compile a
> .NET app, it is actually creating a generic "intermediate language".  It
> is not creating machine CPU instructions, the way a C compiler does
>
> When you run a .NET application, the .NET runtime does a "just-in-time"
> compile, which turns the intermediate language into machine code for
> whatever CPU it is running on.  That's why a single .NET application can
> run in many different systems.
>
> When you build a .NET exe as "any CPU" and run that code on a 64-bit
> system, the JIT compile will turn it into 64-bit code.  That application
> cannot call a 32-bit DLL.  When you build a .NET exe as "Win32" and run
> that code on a 64-bit system, the JIT compile will turn it into 32-bit
> code.  There, the call is OK.  Same exact code, different circumstances.
>
> So, one answer is to build your applications as Win32 instead of "Any
> CPU".  Another possible answer is to turn your COM server into an "out
> of process" COM server.  That way, instead of a DLL, you will have an
> EXE which will run in a separate process.  I do not know how to do that
> with PythonCOM.  Hopefully, Mark will chime in here with a helpful
> suggestion.
>



More information about the python-win32 mailing list