473,749 Members | 2,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiplatform & Interop

If I write a pure C# application, only using the standart publi API, no
interop, the same binary should work well on32 bit, 64 bits and perhaps on
the compact framework as well if I link against it.

Now how could I achieve the same thing if I do interop and I have a managed
C++ API?

let say I have a managed C++ module compiled for 3 different target but with
always the same interface:
mycppmodule32.d ll
mycppmodule64.d ll
mycppmoduleCE.d ll

let say in the C# code I also do some interop
internal class User32 // & CE ?!
{
[DllImport("USER 32")]
public IntPtr GetHdc(IntPtr hWnd); // 4 byte IntPtr
}
internal class User64 // not sure it exists, but I assume....
{
[DllImport("USER 64")]
public IntPtr GetHdc(IntPtr hWnd); // 8 byte IntPtr
}
Let suppose these DLLs are included as modules in my csharpdll.dll.

Now if I deploy all these DLLs, how could write a simple nice code in my C#
dll which internally target whatever native lib is appropriate?
Is it possible (to keep it simple)?
--
Regards,
Lloyd Dupont

NovaMind development team
NovaMind Software
Mind Mapping Software
<www.nova-mind.com>
Jun 20 '06 #1
9 2767
Hi Lloyd!

Consider preparing multiple builds of your C# dll for different platforms,
using conditional compilation directives and constants to include the right
DllImport attributes. Something like:

#if WIN64
[DllImport("user 64", ...]
#else
[DllImport("user 32", ...]
#endif

"Lloyd Dupont" <net.galador@ld > wrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
If I write a pure C# application, only using the standart publi API, no
interop, the same binary should work well on32 bit, 64 bits and perhaps on
the compact framework as well if I link against it.

Now how could I achieve the same thing if I do interop and I have a
managed C++ API?

let say I have a managed C++ module compiled for 3 different target but
with always the same interface:
mycppmodule32.d ll
mycppmodule64.d ll
mycppmoduleCE.d ll

let say in the C# code I also do some interop
internal class User32 // & CE ?!
{
[DllImport("USER 32")]
public IntPtr GetHdc(IntPtr hWnd); // 4 byte IntPtr
}
internal class User64 // not sure it exists, but I assume....
{
[DllImport("USER 64")]
public IntPtr GetHdc(IntPtr hWnd); // 8 byte IntPtr
}
Let suppose these DLLs are included as modules in my csharpdll.dll.

Now if I deploy all these DLLs, how could write a simple nice code in my
C# dll which internally target whatever native lib is appropriate?
Is it possible (to keep it simple)?
--
Regards,
Lloyd Dupont

NovaMind development team
NovaMind Software
Mind Mapping Software
<www.nova-mind.com>


Jun 20 '06 #2

"Lloyd Dupont" <net.galador@ld > wrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
If I write a pure C# application, only using the standart publi API, no
interop, the same binary should work well on32 bit, 64 bits and perhaps on
the compact framework as well if I link against it.

Now how could I achieve the same thing if I do interop and I have a
managed C++ API?

let say I have a managed C++ module compiled for 3 different target but
with always the same interface:
mycppmodule32.d ll
mycppmodule64.d ll
mycppmoduleCE.d ll

let say in the C# code I also do some interop
internal class User32 // & CE ?!
{
[DllImport("USER 32")]
public IntPtr GetHdc(IntPtr hWnd); // 4 byte IntPtr
}
internal class User64 // not sure it exists, but I assume....
{
[DllImport("USER 64")]
public IntPtr GetHdc(IntPtr hWnd); // 8 byte IntPtr
}
Let suppose these DLLs are included as modules in my csharpdll.dll.

Now if I deploy all these DLLs, how could write a simple nice code in my
C# dll which internally target whatever native lib is appropriate?
Is it possible (to keep it simple)?


Hi Lloyd!

IntPtr is platform dependent, so in your sample, you don't have to declare
twice.

I know, this requires a lot of rereading docs before you can be sure, it
works on both platforms. See also DMytro's answer.

Jun 20 '06 #3
Hi,
"Lloyd Dupont" <net.galador@ld > wrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
If I write a pure C# application, only using the standart publi API, no
interop, the same binary should work well on32 bit, 64 bits and perhaps on
the compact framework as well if I link against it.


In the CF you have a VERY limited set of classes and methods inside the
included classes, so the above is not 100% accurate.

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jun 20 '06 #4
Hi Dmytro,

Perhaps I didn't explained my self correctly.

What I was trying to do in a simple manner (if possible) is to have one
library to run them all!

Like imagine my program is a click once application, I would like (if
possible) to avoid the x32 link, the x64 link, the CE link.
Just one link and it runs whatever the end-user machine.

Or also imagine the user "install" (i.e. copy) the file on one PC, and then
he simply copy the file again on an other PC and it still works!

Conditional compilation is a clean way to have one build for each given
platform.
But I wonder if there is a no hassel way to have one build for all platform
that the user could simply copy without worrying about his pc
architecture... .

Do you see what I mean?
Is it possible? (in a simple way)

For exemple a while back I wrote something like the code below so that my
pocket application, using some WinCE specific dll, runs on both the desktop
and CE smoothly.
But it's kind of overkill for a big API.

enum Platform
{
CE,
Win32,
}
public class OSUtil
{
internal static Platform Platform { get {} }

public int AMethod()
{
switch(Platform )
{
case CE:
return OSUtilCE.AMetho d();
case Win32:
return OSUtilWin32.AMe thod();
}
}
}
class OSUtilCE
{
[DllImport("CEDl l")]
static int AMethodImpl();
static int AMethod() { return AMEthodImpl(); }
}
class OSUtil32
{
[DllImport("Win3 2Dll")]
static int AMethodImpl();
static int AMethod() { return AMEthodImpl(); }
}



"Dmytro Lapshyn [MVP]" <x-****@no-spam-please.hotpop.c om> wrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
Hi Lloyd!

Consider preparing multiple builds of your C# dll for different platforms,
using conditional compilation directives and constants to include the
right DllImport attributes. Something like:

#if WIN64
[DllImport("user 64", ...]
#else
[DllImport("user 32", ...]
#endif

"Lloyd Dupont" <net.galador@ld > wrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
If I write a pure C# application, only using the standart publi API, no
interop, the same binary should work well on32 bit, 64 bits and perhaps
on the compact framework as well if I link against it.

Now how could I achieve the same thing if I do interop and I have a
managed C++ API?

let say I have a managed C++ module compiled for 3 different target but
with always the same interface:
mycppmodule32.d ll
mycppmodule64.d ll
mycppmoduleCE.d ll

let say in the C# code I also do some interop
internal class User32 // & CE ?!
{
[DllImport("USER 32")]
public IntPtr GetHdc(IntPtr hWnd); // 4 byte IntPtr
}
internal class User64 // not sure it exists, but I assume....
{
[DllImport("USER 64")]
public IntPtr GetHdc(IntPtr hWnd); // 8 byte IntPtr
}
Let suppose these DLLs are included as modules in my csharpdll.dll.

Now if I deploy all these DLLs, how could write a simple nice code in my
C# dll which internally target whatever native lib is appropriate?
Is it possible (to keep it simple)?
--
Regards,
Lloyd Dupont

NovaMind development team
NovaMind Software
Mind Mapping Software
<www.nova-mind.com>

Jun 20 '06 #5
The trick, of course, is to build against the Compact CF.
Then it runs on the desktop!

Do not worry for I have developed PocketPC application :-)

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:eu******** ******@TK2MSFTN GP05.phx.gbl...
Hi,
"Lloyd Dupont" <net.galador@ld > wrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
If I write a pure C# application, only using the standart publi API, no
interop, the same binary should work well on32 bit, 64 bits and perhaps
on the compact framework as well if I link against it.


In the CF you have a VERY limited set of classes and methods inside the
included classes, so the above is not 100% accurate.

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Jun 20 '06 #6
mhhhh....

perhaps I could still do as below but generate this wrapper code
automatically?
that's an idea!
enum Platform
{
CE,
Win32,
}
public class OSUtil
{
internal static Platform Platform { get {} }

public int AMethod()
{
switch(Platform )
{
case CE:
return OSUtilCE.AMetho d();
case Win32:
return OSUtilWin32.AMe thod();
}
}
}
class OSUtilCE
{
[DllImport("CEDl l")]
static int AMethodImpl();
static int AMethod() { return AMEthodImpl(); }
}
class OSUtil32
{
[DllImport("Win3 2Dll")]
static int AMethodImpl();
static int AMethod() { return AMEthodImpl(); }
}

Jun 20 '06 #7
Lloyd,
Let suppose these DLLs are included as modules in my csharpdll.dll.


Why do you want to deploy that way?

Personally I would, if possible, have three builds of a single library
mycppmodule.dll , and have the installer make sure the correct version
gets installed on the system. That way a single set of DllImports can
work on all platforms (assuming you can write all the signatures in a
way that works everywhere).
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 21 '06 #8
My problem is requiring an installer to have the library working seems
awfully overkill.
I like the simple "xcopy" deployment method and I wonder if I could achieve
it while being multiplatform.. .
Well I huess it's not really pratical...
"Mattias Sjögren" <ma************ ********@mvps.o rg> wrote in message
news:eR******** ******@TK2MSFTN GP02.phx.gbl...
Lloyd,
Let suppose these DLLs are included as modules in my csharpdll.dll.


Why do you want to deploy that way?

Personally I would, if possible, have three builds of a single library
mycppmodule.dll , and have the installer make sure the correct version
gets installed on the system. That way a single set of DllImports can
work on all platforms (assuming you can write all the signatures in a
way that works everywhere).
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Jun 22 '06 #9
Lloyd Dupont wrote:
My problem is requiring an installer to have the library working seems
awfully overkill.
I like the simple "xcopy" deployment method and I wonder if I could achieve
it while being multiplatform.. .
Well I huess it's not really pratical...


Just in case you didn't check there:
I suggested a possible workaround in
microsoft.publi c.dotnet.framew ork.interop,
Jun 22 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1777
by: Simon Roses Femerling | last post by:
Thx for your response sqllite looks very interesting :) Here is the python module: http://sourceforge.net/projects/pysqlite/ I'm familiar with mysql and postgresql but there are too heavy and I dont want to install a database. I'm looking for something like sqllite thx
0
2361
by: roy | last post by:
I try to call com written in VB 6.0. When I use VS.net Studio to do the debuging, some time it works fine, some time I got the following message: Server Error in '/GISOnlineReservation' Application. ----------------------------------------------------------- --------------------- Configuration Error Description: An error occurred during the processing of a
1
2582
by: Bob N5 | last post by:
I am working on an application that uses interop to do some simple operations with both Excel and Word. I have most of functionality working, but ran into issues on making things work with both versions of office. My questions are: 1. What is the 'best' practice for building an application that will work with both versions of office? Do I need to have a separate build with different references for each? 2. Can I install interop...
0
1052
by: Maxim Kazitov | last post by:
Hi, I try to create ObjectBrowser for some COM objects (C# project, I use Interop Assembly for COM). But if following code : Type oType = m_Object.GetType(); always return __ComObject instead of <Interop Class>, is it any way to get
10
1692
by: Michi | last post by:
Hi Does anybody know how I can display own icons for drag & drop ? thx
2
8206
by: Steve | last post by:
I'm using Visual Studio .NET (not 2003), and am developing a class that works with Word theough the Office PIAs (Interop). I can open word and do things with it programatically, but I can't close it. Specifically, when I try to call the Quit() method on the application object, VB gives me the following error: 'Quit' is ambiguous across the inherited interfaces 'Microsoft.Office.Interop.Word._Application' and...
2
2601
by: 1944USA | last post by:
I am re-architecting a C# application written as a multithreaded Windows Service and trying to squeeze every bit of performance out of it. 1) Does the thread that an object is instantiated on have any impact on its performnce? Example: if I instantiate object "X" on thread "A" pass a reference of "X" to Thread "B" and then have "B" run "X" (Exclusively). Does
3
5112
by: Brent | last post by:
I'm trying to open and manipulate an Excel spreadsheet from C#. To that end, I've referenced Interop.EXCEL9.dll, which I have on my machine. All of the examples I've read say to do something like this: -------------------------- Excel.Application xl = new Excel.ApplicationClass(); xl.Visible = "true"; String workbookPath = @"c:\SomeWorkBook.xls"; Excel.Workbook xlW = xlW.Workbooks.Open(workbookPath,0, false, 5, "",
1
1931
by: =?Utf-8?B?UmFq?= | last post by:
I want to understand why C++ interop has better performance than P/Invoke. Can someone explain in detail. Thanks
0
9566
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8256
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.