DllImport Based on OS Platform
Posted
by Ngu Soon Hui
on Stack Overflow
See other posts from Stack Overflow
or by Ngu Soon Hui
Published on 2010-06-14T02:35:57Z
Indexed on
2010/06/14
2:42 UTC
Read the original article
Hit count: 249
I have a mixture of unmanaged code ( backend) and managed code ( front end), as such, I would need to call the unmanaged code from my managed code, using interop techniques and DllImport
attribute.
Now, I've compiled two versions of unmanaged code, for both 32 and 64 bit OS; they are named service32.dll
and service64.dll
respectively. So, in my .Net code, I would have to do a DllImport
for both dlls:
[DllImport(@"service32.dll")] //for 32 bit OS invocation
public static void SimpleFunction();
[DllImport(@"service64.dll")] //for 64 bit OS invocation
public static void SimpleFunction();
And call them depending on which platform my application is running on.
The issue now is that for every unmanaged function, I have to declared it twice, one for 32 bit OS and one for 64 bit OS. This is a duplication of work, and everytime I change the signature of an unmanaged function, I have to modified it in two places.
Is there anyway that I can change the argument in DllImport
so that the correct dll will be invoked automagically, depending on the platform?
© Stack Overflow or respective owner