473,698 Members | 2,305 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing values from C# from/to a C++ dll

Hi, I have this in C++ and I like to call it from c# to get the value
but I fail. it will be good if you can give me some information. I
tried it in VB.net it works but I use almost the same way as VB in C#
but it doens't work.

c++: (csp2.dll)
NoMangle long DLL_IMPORT_EXPO RT csp2TimeStamp2S tr(unsigned char
*Stamp, char *value, long nMaxLength);


VB.net: (this works correctly)

Declare Function csp2TimeStamp2S tr Lib "csp2.dll" (ByRef Stamp As
Byte, ByVal value As String, ByVal nMaxLength As Integer) As Integer

Dim nRC As Integer
Dim arrbyteBarcode( 99) As Byte '100 elements
Dim nBytesRead As Integer
Dim bstrTmp As New VB6.FixedLength String(50)

nBytesRead = csp2GetPacket(a rrbyteBarcode(0 ), i, 100)

nRC = csp2TimeStamp2S tr(arrbyteBarco de(nBytesRead - 4), bstrTmp.Value,
Len(bstrTmp.Val ue))
TextBox1.text= VB.Left(bstrTmp .Value, 20)


C#: (this doesn't work :( )

[System.Runtime. InteropServices .DllImport("csp 2.DLL")] static extern
int csp2TimeStamp2S tr(byte value, string Stamp, int nMaxLength);

int nRC, nBytesRead;
byte[] arrbyteBarcode= new byte[100];
FixedLengthStri ng bstrTmp = new FixedLengthStri ng(50);

nBytesRead = csp2GetPacket(a rrbyteBarcode[0], i, 100);
bstrTmp=" ";

nRC = csp2TimeStamp2S tr(arrbyteBarco de[nBytesRead-4],
bstrTmp.Value, bstrTmp.Value.L ength);
TextBox1.text= bstrTmp.Value.t oString();

Oct 3 '07
11 7188

"Bob Yang" <bo******@gmail .comwrote in message
news:11******** **************@ 57g2000hsv.goog legroups.com...
thank you! great information.

2. if I have a c++ as (unsigned char[] ca1, char[] ca2), how can I
call it correctly in c#? is it equal to (byte[] ca1, byte[] ca2)?
More precisely ca2 would be sbyte[], but byte[] should also work.
Moreover, ca1 and ca2 are only passing IN the the value and c++ cannot
change the value because it is not a pointer in c++?
The DLL cannot change the caller's variable to a different array. It can
however change the content of the array passed in the call, which is shared
with the caller.
Oct 8 '07 #11
Please read the following article:
http://blog.rednael.com/2008/08/29/M...DLLsInNET.aspx

It's an in depth article about marshalling between native code and managed code. It shows which types are interoperable, how to import a DLL, how to pass strings, how to pass structures and how to de-reference pointers.

Code examples in C# are included.
Sep 10 '08 #12

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

Similar topics

1
7784
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains: ---------------------------------------------------------------------------- <?php ini_set("session.use_cookies", "off"); ini_set("session.use_trans_sid", "on"); session_start(); $_SESSION = ""; $_SESSION = ""; echo "<form method='POST' action='login.php'>
12
6548
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the courses to pass the correct option value and then be displayed at the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html I am passing countries, products, and courses. The first two display
3
14939
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
2
4589
by: Gordon Hudson | last post by:
Hello Here is what I am trying to do: Make a hyperlink on a data entry form with its URL built from the values for fields in that entry on the database. So, I would go to record 65785 click on the link and it would open a web page. The URL contained in the hyperlink would pass the name and address field
2
1927
by: craigkenisston | last post by:
Hi, I created an array of objects like this : object Values = {myObject.myprop, otherobject.otherprop, thirdobject.xprop}; Then I pass it to a method. and I get the values filled in that method. I can debug the method and values are being assigned. But when I am in the calling procedure I no longer see the values, I
1
2708
by: olduncleamos | last post by:
Hello all. With a background in ASP, I am finding the work required for passing values between pages mystifying. For various obvious reasons, I have eliminated using cookies and session to store state data. The only ASP.NET options left is to use the Server.Transfer to transfer to page 2 from page 1, and then use the context to get whatever values in page 1 from page 2. I do find this indeed a very elegant solution as now I can pass...
11
8124
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line number) which is the last line of the following sub routine: ' procedure modifies elements of array and assigns ' new reference (note ByVal) Sub FirstDouble(ByVal array As Integer()) Dim i As Integer
1
2114
by: vncntj | last post by:
I have a C#.NET that simply passes 6 values to a Stored Procedure. But I'm trying to get the (Default.aspx.cs page) to handle passing the values to the sp. The goal is to pass the values and see if any records are returned. I will later insert some conditional statements. Here is my Default.aspx.cs protected void btnNext_Click(object sender, EventArgs e) {
3
2127
by: ishwarbg | last post by:
Hi Everyone, I have a .Net Application, through which I am invoking a function from a legacy DLL developed in C++. My structure in C# contains some data of type double which I need to pass to to the DLL to get some results back from it. My Structure In C# looks like this: public struct InputPurchaseOrder { public System.String poJobName;
5
3204
by: jmartmem | last post by:
Greetings, I have built an Update Record Form in an ASP page. This form contains a number of fields, such as text boxes and menus, to name a few. Upon clicking the 'submit' button, I want the form values to pass to a confirmation page that shows the values entered and selected, with a CDONTS auto email generated at the same time. My problem is that I'm having trouble passing the values from the form to both the confirmation page and the...
0
8674
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9157
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9027
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8895
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2329
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.