PC Review


Reply
Thread Tools Rate Thread

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

 
 
Aristotelis E. Charalampakis
Guest
Posts: n/a
 
      17th Aug 2004
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.


 
Reply With Quote
 
 
 
 
Tom Shelton
Guest
Posts: n/a
 
      17th Aug 2004
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]
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      17th Aug 2004
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



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      17th Aug 2004
* "Aristotelis E. Charalampakis" <(E-Mail Removed)> 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/>
 
Reply With Quote
 
Aristotelis E. Charalampakis
Guest
Posts: n/a
 
      17th Aug 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: over written folder full of work Gord Dibben Windows XP General 2 7th Mar 2010 12:31 AM
Re: over written folder full of work EN59CVH Windows XP General 0 5th Mar 2010 11:09 PM
Will an IE Band written in c# work on all OS's ? Dave Microsoft Dot NET Framework Forms 3 3rd May 2004 10:24 AM
Will an IE Band written in c# work on all OS's ? Dave Microsoft C# .NET 2 3rd May 2004 10:24 AM
is the driver written for XP will work 100% on XP embedded? Patrick Zou Windows XP Embedded 2 10th Jul 2003 07:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:39 PM.