473,322 Members | 1,620 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,322 software developers and data experts.

Dll written in C++ 6.0, will it work in vb.net?

Hello all,

I suppose that this question is not uncommon, but I am unable to google the
answer. I have written a dll in C++ 6.0 (Math only!) which works perfectly
with VB 6.0.

Now that I am ready to pass to the .NET era, the question is simple: Will it
work? Do I have to make some modifications? Are there any problems with the
data types (doubles, floats etc)? how about strings?

Any insight will be appreciated. I want to be certain about this before I
start improving the dll (I dont want this work to be wasted - I ve seen this
movie before!)

TIA,

A.
Nov 21 '05 #1
4 1419
On Tue, 17 Aug 2004 09:34:37 +0300, Aristotelis E. Charalampakis wrote:
Hello all,

I suppose that this question is not uncommon, but I am unable to google the
answer. I have written a dll in C++ 6.0 (Math only!) which works perfectly
with VB 6.0.

Now that I am ready to pass to the .NET era, the question is simple: Will it
work? Do I have to make some modifications? Are there any problems with the
data types (doubles, floats etc)? how about strings?

Any insight will be appreciated. I want to be certain about this before I
start improving the dll (I dont want this work to be wasted - I ve seen this
movie before!)

TIA,

A.


If it worked in VB6 - then it will work in VB.NET. There are a couple of
things to be aware of though :)

1. Data type sizes have changed. In VB6 Integer is 16-bit and Long was
32-bit. In VB.NET, Short is 16-bit, Integer is 32-bit, and Long is 64-bit.
What that means, is that where you used Long in VB6, you'll want to use
Integer in VB.NET.

2. Strings - hmm, I'm not sure how to answer this one... See, for the most
part VB.NET lets you marshall strings pretty much the same way as you did
in VB6 (though, you can now call Unicode functions directly)... This is
fine, except if the API call is going to actually modify the string buffer.
In those cases it is better to declare your function as taking
System.Text.StringBuilder rather then String. This is more efficeint -
since StringBuilder is designed to be a mutable buffer, where is string is
designed to be immutable. Besides, even if the overhead doesn't bother you
- you have to do it that way in C# :)

3. Passing of structures (UDT's in VB6) is a bit different, but much more
flexible - in fact, you can even simulate unions by applying the right
marshaling attributes... No more byte array and RtlMoveMemory tricks
(Yay!).

Anyway, if you look up P/Invoke in the docs, you should be on your way.
There is a section on default marshaling and such that would probably be
helpful to you. If you have any further questions problems, feel free to
post here and I'm sure someone can lend you a hand.

--
Tom Shelton [MVP]
Nov 21 '05 #2
Aristotelis,

(copied from MSDN)

The Visual Basic 6.0 Long data type is now the Visual Basic .NET Integer
data type, and the Visual Basic 6.0 Integer data type is now the Visual
Basic .NET Short data type.

I hope this helps?

Cor

Nov 21 '05 #3
* "Aristotelis E. Charalampakis" <ar********@technologismikiREMOVEIT.com> scripsit:
I suppose that this question is not uncommon, but I am unable to google the
answer. I have written a dll in C++ 6.0 (Math only!) which works perfectly
with VB 6.0.

Now that I am ready to pass to the .NET era, the question is simple: Will it
work? Do I have to make some modifications? Are there any problems with the
data types (doubles, floats etc)? how about strings?


It will work with VB.NET.

Keywords: P/invoke, 'Declare', 'DllImportAttribute'. There is a lot of
information about these topics available in the documentation.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #4
Sure it helps... Thanks both of you. 8-]

Well, I don't mind declaring the functions to return integer instead of
long... Since the double data type has not changed, I should be ok.

Howrver, the UDTs issue is very important; Up to now I worked like this:
/*
In order to use within VB, add these types:

Public Type wPoint2D
X As Single
Y As Single
End Type

Public Type wLine2D
P1 As wPoint2D
P2 As wPoint2D
End Type
*/

/*
================================================== =========================

w3Point2DIsLeft(): Test if a point is Left|On|Right of an infinite line

Input: Pointer to three wPoint2D structures, Pt0, Pt1, Pt2
Returns: >0 if Pt2 left of the line
=0 if Pt2 on the line
<0 if Pt2 right of the line
Use within VB:
Public Declare Function w3Point2DIsLeft Lib "mydll.dll" (wPoint2D0 As Any,
wPoint2D1 As Any, wPoint2D2 As Any) As Single

================================================== =========================
*/
float _stdcall w3Point2DIsLeft( wPoint2D* Pt0, wPoint2D* Pt1, wPoint2D* Pt2)
{
return (float)( (Pt1[0].X-Pt0[0].X)*(Pt2[0].Y-Pt0[0].Y)
- (Pt2[0].X-Pt0[0].X)*(Pt1[0].Y-Pt0[0].Y) );
}

also:

typedef struct {float X, Y;} wPoint2D;
typedef struct {wPoint2D P1, P2;} wLine2D;

Since I am not a master in C++, I am not really sure if this is the optimal
way to work.

I guess this is way off topic, though.

Thanx a lot.

A.
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:Oe**************@TK2MSFTNGP10.phx.gbl...
Aristotelis,

(copied from MSDN)

The Visual Basic 6.0 Long data type is now the Visual Basic .NET Integer
data type, and the Visual Basic 6.0 Integer data type is now the Visual
Basic .NET Short data type.

I hope this helps?

Cor

Nov 21 '05 #5

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

Similar topics

7
by: winlinchu | last post by:
Hi! I use Python, and writing some extension modules I think which could be written an C compiler, useful only to compile extension modules (I not think an GCC!!!!), so that the user not have to...
9
by: JeffFinnan | last post by:
I can get a source file to write html code fully in Iexplorer. However, in Netscape 4.8, I cannot get it to write this particular line: <SCRIPT LANGUAGE="JavaScript" SRC="src1.js"></script> in the...
9
by: TCMA | last post by:
I am looking for some tools to help me understand source code of a program written in C++ by someone else. Are there any non-commercial, open source C or C++ tools to reverse engineer C or C++...
8
by: Maverick | last post by:
I want to group all the javascript functions into a file named MiscFunc.js in a asp.net project. ======================================== e.g. In MiscFunc.js function dummyFunc(var1, var2) {...
132
by: Kevin Spencer | last post by:
About 2 years ago, and as recently as perhaps 1 year ago, I can recall seeing many posts about what language to use with ASP.Net. The consensus was that employers paid more for C# programmers, and...
13
by: Shailesh Humbad | last post by:
Here is an advanced PHP question. Can anyone think of a way to detect the number of bytes written to output when a script is aborted? I am sending a large file to the client, and I want to record...
2
by: AccessCoder | last post by:
What is the proper way to reference code snippets that are copied from usenet group examples? What about when a developer posts code that is copyrighted and they allow you to use it in a...
14
by: Erwin Moller | last post by:
Java + PHP, Ruby+PHP, Ruby + C++, or what else?
61
by: giveitawhril2008 | last post by:
I'm just learning about Python now and it sounds interesting. But I just read (on the Wiki page) that mainstream Python was written in C. That's what I was searching for: Python was written in what...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.