473,395 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

to deal with C++ OLE in C# code.

Hi Everyone ,
I badly stuck up in C# application which use C++ OLE to communicate with a
device to get data from device.
I converted C++ code into C# to build this application but still using C++
OLE. I couldnot get any data from device through OLE.
Can some help me?
Following is an 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.

************************************************** *****************************/
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;
}


converted C# code:
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;
}
Help me as early as possible.
Regards,
--
atul baxi
Aug 27 '08 #1
0 931

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

Similar topics

6
by: Alex Shi | last post by:
Any good idea or a reference link to deal with search engine for php web pages? Thanks in advance! Alex
9
by: _mario lat | last post by:
I'd like to deal (update, deal, insert....) a database (with tables and relationship between these) by a tool written in php. I need to share and work on a database with other people. I'd like to...
23
by: Steve Jorgensen | last post by:
Hi all, I'm working on a project through a consulting company, and I'm writing some database code for use in another programmer's project in Excel/VBA. The other programmer is working through...
1
by: Davy | last post by:
My program deal with a several level tree with several branchs. The amount of branchs from father node is not known. So I want to creat a tree with dynamic branchs. Now I use the structure:...
5
by: Amr | last post by:
Hi i need a library to deal with the modem, cause i have to make an application that connect to the modem and deal a number, and wirte the events (busy, answered, not answered)
7
by: rbt | last post by:
The house almost always wins or are my assumptions wrong... import random amounts = results = count = 0 while count < 10:
0
by: AWHF | last post by:
hey, is there anyone who know how to deal with vector? i have 2 files as below: file1.doc ::component list ::Start green in grp1 blue in grp2
89
by: Tubular Technician | last post by:
Hello, World! Reading this group for some time I came to the conclusion that people here are split into several fractions regarding size_t, including, but not limited to, * size_t is the...
2
by: mk | last post by:
Hello, I'm trying to learn how with statement can be used to avoid writing: prepare() try: something_that_can_raise_SomeException() except SomeException, err: deal_with_SomeException...
0
by: Jorgen Bodde | last post by:
Hi Edwin, Filemask is obvious as it is assigned in the python code itself. It is "%file%". The idea is that the file clicked is substituted for the "%file%" by the replace action. The file that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.