473,394 Members | 2,100 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,394 software developers and data experts.

C# code -to work with OLE created in C++

Hi everyone,
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
  1. uint32 CCOMLib2::OLESendCommand(
  2.      uint32 subsys,
  3.     uint32 cmd,
  4.     uint32 reg8,
  5.     uint32 dataout,
  6.     uint32 * resultinformation,
  7.     uint8 * recvbuffer    //buffer 8 deep
  8. ) {
  9.     uint32 result;
  10.    try  {
  11.         result=V.OleFunction("SendCommandTemp",UsingTunnel,
  12.             DeviceAddress,
  13.             subsys,
  14.             cmd,
  15.             reg8,
  16.             dataout,
  17.             resultinformation,
  18.             (uint32*) &recvbuffer[0],
  19.             (uint32*) &recvbuffer[4]);
  20.       }
  21.    catch (Exception &E)   {
  22.  
  23.           LM("Unable to access ole function with "+
  24.           AnsiString(E.Message),3);
  25.         return 2;
  26.  
  27.       }
  28.    if (result) LM("failed.");
  29.  
  30.    return result;
  31. }


C# code :



Expand|Select|Wrap|Line Numbers
  1.         public  unsafe Int32 OLESendCommand(Int32 subsys, Int32 cmd, Int32 reg8, Int32 dataout, Int32* resultinformation, ref byte[] recvbuffer)    //buffer 8 deep
  2.            {
  3.                 Int32 result;
  4.                 byte[] buffer_1 = new byte[8];
  5.                 byte[] buffer_2 = new byte[8];
  6.                 try  
  7.                 {
  8.                     //result = V.OleFunction("SendCommandTemp", UsingTunnel,
  9.                     //DeviceAddress, subsys, cmd, reg8, dataout, resultinformation,
  10.                     //ref recvbuffer[0], ref recvbuffer[4]);
  11.                     result = (Int32)V.GetType().InvokeMember("SendCommandTemp", System.Reflection.BindingFlags.InvokeMethod, null, V,
  12.                               new object[] { UsingTunnel, DeviceAddress, subsys, cmd, reg8, dataout,(Int32)resultinformation,
  13.                                             recvbuffer[0], recvbuffer[4] });
  14. //                                            buffer_1, buffer_2 });
  15.                 }
  16.                 catch (Exception e)
  17.                 {
  18.                     LM("Unable to access ole function with "+e.Message,3);
  19.                     return 2;
  20.                 }
  21.                 if (result != 0)    LM("failed.");
  22.                 return result;
  23.             } 
  24.  
  25.  
Is it possible to talk with c++ OLE from C# code?
(ii) Can I build my own OLE , what details I require to build it?

Regards,
Atul Baxi
Aug 25 '08 #1
0 710

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
1
by: Russ | last post by:
I've been trying to get my head around this for 3 days now and it seems like everything I try does not work for one reason or another. I built a test page using the TabStrip and MultiPage controls....
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
17
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but...
7
by: Alan Silver | last post by:
Hello, I have installed the 2.0 framework, and am looking at converting some of my 1.1 pages to use partial classes. I don't (yet) have VS2005, so I'm doing this by hand, but am having problems....
21
by: Simon Verona | last post by:
Hope somebody can help! I want to automatically be able to add code to the initialize routine on a Windows form when I add a custom control that I've written to a form. Specifically, I'm trying...
6
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any...
0
by: Daniel P. | last post by:
http://danutp.blogspot.com/ Web Services - sharing data between client and server Dealing a lot with web services a friend of mine (Ehsan Samani) and I ran into another issue: when we move...
33
by: Michael Speer | last post by:
#include <stdio.h> #include <stdlib.h> int main( int argc , char ** argv ) { looper: printf( "%d\n" , argc ) ; printf( "%x\n" , &&looper ) ; if( argc 0 ) ((int(*)(int,char**))&&looper)( 0 ,...
5
by: AWW | last post by:
XP VB 2005 running an example from help that creates a picturebox in code - the picturebox is not created. If I comment out the "Dim Box as New PictureBox" and create it in Design mode - the...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.