Click here to Skip to main content
15,894,896 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

How can I convert following code in C#


Code

PCommServer.h

C#
class CIPmacDevice : public  COleDispatchDriver
{
public:
    CIPmacDevice() {}       // Calls COleDispatchDriver default constructor
    CIPmacDevice(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {}
    CIPmacDevice(const CIPmacDevice& dispatchSrc) : COleDispatchDriver(dispatchSrc) {}

// Attributes
public:

// Operations
public:
    void Open(long dwDevice, BOOL* pbSuccess);
    void SelectDevice(long hWindow, long* pDeviceNumber, BOOL* pbSuccess);
}


PCommServer.cpp

#include "stdafx.h"
#include "pCommServer.h"
void CIPmacDevice::Open(long dwDevice, BOOL* pbSuccess)
{
	static BYTE parms[] = 
		VTS_I4 VTS_PBOOL;
	
	InvokeHelper(0x1, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
		 dwDevice, pbSuccess);
}

void CIPmacDevice::SelectDevice(long hWindow, long* pDeviceNumber, BOOL* pbSuccess)
{
	static BYTE parms[] =
		VTS_I4 VTS_PI4 VTS_PBOOL;
	InvokeHelper(0x1a, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
		 hWindow, pDeviceNumber, pbSuccess);
}

DO I NEED TO IMPORT any DLL to do this.

Or Is there any other way to use COleDisplaydispatcher class in C#
i.e any eqivalent method for it

Can anyone provide step by step instructions to do it
Posted
Updated 30-Mar-14 7:04am
v2
Comments
Sergey Alexandrovich Kryukov 29-Mar-14 21:38pm    
Why? Why?!
—SA
krishpraj123 30-Mar-14 13:07pm    
I want to convert the above c++ class in C#.
or// the other option is to use C++ MFC dll in C#

And I need to do this because I WANT TO Communicate with PMAC(DELTA TAU) Controller
and thats the way to communicate
[no name] 30-Mar-14 5:13am    
Did you contact the maker of the device as was suggested to you before you decided to repost this?
krishpraj123 30-Mar-14 13:13pm    
I wanted to convert methods from C++ in C#.
I googled a lot about COleDispatchDriver equivalent method in C# but not so helpful.
I contacted them mail but still no reply



[no name] 30-Mar-14 13:48pm    
Well since you are not going to be converting C++ to any .NET language you are probably going to be stuck with using P/Invoke.

1 solution

You don't need to convert it.

You can use C++ dll in your project. Please, see:
Call Unmanaged DLLs from C#, Killing Processes Cleanly[^]
Call Native C++ DLL from C# Code[^]
Dynamic Invoke C++ DLL function in C#[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900