In Progress

Experimental code involving marshalling

Write C# code (no C++/CLI wrapper) that makes use of Marshaling involving accessing the virtual function table and create delegates to each functions.

//Test.h

struct Something

{

int i;

char s[32];

};

class CTestInterface

{

public:

virtual int __stdcall QueryInterface(REFIID riid,LPVOID* obj)=0;

virtual int __stdcall AddRef() =0;

virtual int __stdcall Release()=0;

virtual void __stdcall DoSomething();

virtual int __stdcall GetSomething(Something* s)=0;

};

typedef int (*TestVersion)(void);

typedef int (*TestCreate)(int version, CTestInterface **test);

--------------------------------------

[url removed, login to view]

[UnmanagedFunctionPointer([url removed, login to view])]

private delegate int TestVersion();

IntPtr ptr = LoadLibrary(@"[url removed, login to view]");

IntPtr ptr2 = GetProcAddress(ptr, "TestVersion");

TestVersion version = (TestVersion)[url removed, login to view](ptr2, typeof(TestVersion));

[url removed, login to view]("version = " + version());

//???

// TestCreate functions???

// [url removed, login to view]() ??

// [url removed, login to view](....) ??

If you are going to post template replies please don't bid.

if you don't know what is going on, please don't bid.

if you think you can do it but is unsure how, please don't bid

bid only if you have done pure C# pinvoke interop involving virtual table or similar, including callbacks.

In C++, someone will use the following

http://codepad.org/yfZI1Yd9

class CTestFactory
{
private:
HMODULE m_lib;
TestVersion m_Version;
TestCreate m_Create;
public:
//--- constructor
CTestFactory(LPCSTR lib_path=NULL):m_lib(NULL)
{
Init(lib_path);
}
//--- destructor
~CTestFactory()
{
if(m_lib)
{
TestVersion=NULL;
TestCreate =NULL;
::FreeLibrary(m_lib);
m_lib=NULL;
}
}
//--- initialization
inline void Init(LPCSTR lib_path=NULL)
{
char path[256]="";
//---
if(lib_path!=NULL)
{
strcpy_s(path,lib_path);
path[sizeof(path)-1]=0;
}
else
{
#ifndef _WIN64
strcpy_s(path,"Test.dll");
path[sizeof(path)-1]=0;
#else
strcpy_s(path,"Test64.dll");
path[sizeof(path)-1]=0;
#endif
}
//---
if(m_lib)
::FreeLibrary(m_lib);
if((m_lib=::LoadLibraryA(path))!=NULL)
{
TestVersion=reinterpret_cast<TestVersion>(::GetProcAddress(m_lib,"Version"));
TestCreate =reinterpret_cast<TestCreate>(::GetProcAddress(m_lib,"Create"));
}
else
{
TestVersion=NULL;
TestCreate =NULL;
}
//---
}
//--- winsock startup/cleanup
inline int WinsockStartup() const
{
WSADATA wsa;
return(WSAStartup(0x0202,&wsa)!=0 ? RET_ERROR:RET_OK);
}
inline void WinsockCleanup() const
{
WSACleanup();
}
//---
inline int IsValid() const
{
return(m_lib!=NULL && TestVersion!=NULL && TestCreate!=NULL) ? TRUE:FALSE;
}
inline int Version() const
{
return(TestVersion?(*TestVersion)():0);
}
inline CTestInterface* Create(const int version) const
{
CTestInterface *man=NULL;
if(TestCreate) (*TestCreate)(version,&man);
return(man);
}
};

Please refer to http://codepad.org/TCV80FoE for correct code.

Skills: .NET, C# Programming, C++ Programming

See more: write programming code, wrapper programming, virtual int, virtual char, struct c programming, int i, cs programming, c programming typedef, c programming struct, c programming char, cplusplus struct, char c programming, obj c, wrapper cli, create obj, class wrapper, marshaling, wrapper class, loadlibrary, cli programming, ptr, console table, console wrapper, struct, wrapper console

About the Employer:
( 18 reviews ) Singapore, Singapore

Project ID: #6374085

Awarded to:

Karu1977

Hi. Is it required by some reason to create C# wrapper this way? Definition typedef int (*TestVersion)(void); is not correct for method CTestInterface::DoSomething, because methods have hidden first parameter - " More

$250 SGD in 3 days
(2 Reviews)
4.5

5 freelancers are bidding on average $491 for this job

ta0soft

Hi I would be happy to help with your project :) I have over 10 years of experience with C# and C++, I specialize in Windows applications and GUI design. I also have lots of experience with COM interop and marshaling. More

$250 SGD in 10 days
(30 Reviews)
4.7
murtaza1981

Hi, Please feel free to discuss the project with me............................................................................. Thanks, Murtaza

$650 SGD in 14 days
(12 Reviews)
4.6
ravirathorevw

Hi, I am a .Net professional with 12+ years of experience in design and development of web and enterprise applications for distributed Client/Server Real Time Systems, POS systems & Enterprise Web Applications using A More

$750 SGD in 10 days
(7 Reviews)
3.3
jitendraprajapat

Hello I am jitendra prajapat software developer of .net , I have 4+ Exp in .net and different technology, 1..Net Technologies 2. C, C++ , Core Java , Advanced Java , Python [url removed, login to view] , Wordpress, Joomla, Mengendo.etc.. More

$555 SGD in 10 days
(3 Reviews)
2.7
patelbrijesh1309

Hello We are software developement Company of .net , I have 4+ Exp in .net and different technology, 1..Net Technologies 2. C, C++ , Core Java , Advanced Java , Python [url removed, login to view] , Wordpress, Joomla, Mengendo.etc.. 4. More

$700 SGD in 15 days
(1 Review)
2.2
amargurna

I have 5+ years quality experience in ASP.NET, C# 3.5/4.0/4.5, WCF and VB.NET 3.5/4.0 >>> I know C# (and VB.NET) inside out and won't disappoint with my skills with MVC (including Razorview, Prism 4) and UI/Front-en More

$555 SGD in 5 days
(0 Reviews)
0.0