Bonjour,
J'ai une machine sous Windows CE 4.2. Sur celle-ci j'ai un script écrit dans un langage propriétaire qui appelle une dll écrite en C++. Cette DLL est écrite en C++ avec EVC++, c'est du code non managé (pas le choix du au langage propriétaire qui ne peut appeler que des DLL non managées). Je souhaiterais à partir de cette DLL appeler une autre DLL, qui elle serait écrite en C# avec Visual Studio 2003 et est donc du code managé. Comment puis-je faire cela si tenté que cela soit possible sous windows CE ?
J'ai trouvé des exemples d'utilisation de DLL managées à partir de code C++ non managé qui fonctionne très bien sous windows XP. Ces exemples utilisent un client COM (la dll en C++) et un server COM (la dll en c# qui est utilisé par le client COM en c++). Problème je n'arrive pas du tout à faire fonctionner le client en C++ sous EVC++ (donc pour windows CE et non plus windows xp)...
Ci-dessous le code du client COM que je souhaiterais pour porter sur ma plateforme Windows CE 4.2:
Code C/C++ :
// COMClient.cpp
// Build with "cl COMClient.cpp"
// arguments: friend
#include <windows.h>
#include <stdio.h>
#pragma warning (disable: 4278)
// To use managed-code servers like the C# server,
// we have to import the common language runtime:
#import <mscorlib.tlb> raw_interfaces_only
// For simplicity, we ignore the server namespace and use named guids:
#if defined (USINGPROJECTSYSTEM)
#import "..\RegisterCSharpServerAndExportTLB\CSharpServer.tlb" no_namespace named_guids
#else // Compiling from the command line, all files in the same directory
#import "CSharpServer.tlb" no_namespace named_guids
#endif
int main(int argc, char* argv[])
{
IManagedInterface *cpi = NULL;
int retval = 1;
// Initialize COM and create an instance of the InterfaceImplementation class:
CoInitialize(NULL);
HRESULT hr = CoCreateInstance(CLSID_InterfaceImplementation,
NULL, CLSCTX_INPROC_SERVER,
IID_IManagedInterface, reinterpret_cast<void**>(&cpi));
if (FAILED(hr))
{
printf("Couldn't create the instance!... 0x%x\n", hr);
}
else
{
if (argc > 1)
{
printf("Calling function.\n");
fflush(stdout);
// The variable cpi now holds an interface pointer
// to the managed interface.
// If you are on an OS that uses ASCII characters at the
// command prompt, notice that the ASCII characters are
// automatically marshaled to Unicode for the C# code.
if (cpi->PrintHi(argv[1]) == 33)
retval = 0;
printf("Returned from function.\n");
}
else
printf ("Usage: COMClient <name>\n");
cpi->Release();
cpi = NULL;
}
// Be a good citizen and clean up COM:
CoUninitialize();
return retval;
}
Merci