I am stuck with the problem like i am converting c++ code to C#. Now I am trying to get data from the system through OLE which is written in c++(that part I have to use as it is). My C# code able to talk with OLE, but not able to get data from it.
Following is the some example..
C++ code:
/************************************************** *****************************
OLESendCommand
the function used to send and receive data from the device
The public member variable 'UsingTunnel' is passed to the OLE function.
subsys : the subsystem
cmd : the command
reg8 : an option byte that is the fourth transmitted byte
dataout : 32 bit, little endian data.
this forms the payload bytes 4,5,6,7 (out of 0,1,2,3,4,5,6,7)
*resultinformation : this is the result returned from the transaction
often will be RET_ACK or RET_DATA32 or RET_NAK.
*recvbuffer : must be supplied with a uchar buffer 8 bytes long.
generally, only the first four bytes are filled, corresponding to the bytes
4,5,6,7 out of (0,1,2,3,4,5,6,7)
up to 8 bytes can be returned for long format commands
A non zero value is returned if there was no reply from the device.
************************************************** *****************************/
Expand|Select|Wrap|Line Numbers
- uint32 CCOMLib2::OLESendCommand(
- uint32 subsys,
- uint32 cmd,
- uint32 reg8,
- uint32 dataout,
- uint32 * resultinformation,
- uint8 * recvbuffer //buffer 8 deep
- ) {
- uint32 result;
- try {
- result=V.OleFunction("SendCommandTemp",UsingTunnel,
- DeviceAddress,
- subsys,
- cmd,
- reg8,
- dataout,
- resultinformation,
- (uint32*) &recvbuffer[0],
- (uint32*) &recvbuffer[4]);
- }
- catch (Exception &E) {
- LM("Unable to access ole function with "+
- AnsiString(E.Message),3);
- return 2;
- }
- if (result) LM("failed.");
- return result;
- }
C# code :
Expand|Select|Wrap|Line Numbers
- public unsafe Int32 OLESendCommand(Int32 subsys, Int32 cmd, Int32 reg8, Int32 dataout, Int32* resultinformation, ref byte[] recvbuffer) //buffer 8 deep
- {
- Int32 result;
- byte[] buffer_1 = new byte[8];
- byte[] buffer_2 = new byte[8];
- try
- {
- //result = V.OleFunction("SendCommandTemp", UsingTunnel,
- //DeviceAddress, subsys, cmd, reg8, dataout, resultinformation,
- //ref recvbuffer[0], ref recvbuffer[4]);
- result = (Int32)V.GetType().InvokeMember("SendCommandTemp", System.Reflection.BindingFlags.InvokeMethod, null, V,
- new object[] { UsingTunnel, DeviceAddress, subsys, cmd, reg8, dataout,(Int32)resultinformation,
- recvbuffer[0], recvbuffer[4] });
- // buffer_1, buffer_2 });
- }
- catch (Exception e)
- {
- LM("Unable to access ole function with "+e.Message,3);
- return 2;
- }
- if (result != 0) LM("failed.");
- return result;
- }
(ii) Can I build my own OLE , what details I require to build it?
Regards,
Atul Baxi