VB.net / C++ Interoperability

Using a c++ class in a VB.NET project

Page 1 of 1

6 Replies - 4051 Views - Last Post: 29 May 2009 - 11:14 AM Rate Topic: -----

#1 the_hangman  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 13
  • View blog
  • Posts: 602
  • Joined: 18-January 06

VB.net / C++ Interoperability

Posted 28 May 2009 - 01:42 PM

I have a project that I am working on in VB.NET that has to do with cropping extremely large images (like over a gig). The files are too large to just load up as bitmaps, so I am trying to stream the file in straight from the disk. I don't really know how to do this in VB.NET, and I barely have an understanding of it through C++.

So long story short, I have a C++ class that I think should do what I need, but I need to incorporate it into my VB.NET code. I understand it needs to be compiled as a DLL and referenced in, but I have no idea how to do that.

Any one have any ideas? I'm going to include the cpp/h files just for the hell of it

(p.s. I'm not really looking for work-arounds on how to just do the image streaming in VB. Unless it's really really good)

thnx

Attached File(s)


This post has been edited by the_hangman: 28 May 2009 - 01:44 PM


Is This A Good Question/Topic? 0
  • +

Replies To: VB.net / C++ Interoperability

#2 woodjom  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 29
  • View blog
  • Posts: 549
  • Joined: 08-May 08

Re: VB.net / C++ Interoperability

Posted 28 May 2009 - 08:01 PM

what you need to do is include a reference to the DLL. Make sure it is copied to the BIN directory so it can be packaged with the app if you do a setup deployment project.

in VS, goto Project, Add Reference, Browse tab, then goto the location of the DLL and click OK.

Since its your DLL you should know the namespace, class, methods available.
Was This Post Helpful? 0
  • +
  • -

#3 the_hangman  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 13
  • View blog
  • Posts: 602
  • Joined: 18-January 06

Re: VB.net / C++ Interoperability

Posted 29 May 2009 - 06:39 AM

Someone was telling me that I had to have something like [DLL IMPORT(yadda yadda).manifest] or something in the code somewhere.

Do I need the manifest files or do i just import the the DLL file?
Was This Post Helpful? 0
  • +
  • -

#4 woodjom  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 29
  • View blog
  • Posts: 549
  • Joined: 08-May 08

Re: VB.net / C++ Interoperability

Posted 29 May 2009 - 06:50 AM

View Postthe_hangman, on 29 May, 2009 - 07:39 AM, said:

Someone was telling me that I had to have something like [DLL IMPORT(yadda yadda).manifest] or something in the code somewhere.

Do I need the manifest files or do i just import the the DLL file?


This used to be the case in VB6 and .Net 1.0 development. But with 2.0-3.0 (not sure about 3.5 yet) the ability is still there but VS 2k5 (.Net 2.0) it put the references automatically in the application manifest file. There are some instances where the method/property maybe protected and in order for you to access them you have create a instance object to the method/property in order to take advantage of that. Unfortunately, i dont remember how to do that specifically, but have had others more focused on the "Force" to do it for me.

Ill get back to you this afternoon once i get home. Dont have all my juicy application code references at work.

You dont always have to use a DLL import. Add a reference to the DLL through the "My Project\References" click on "Add" and go thru the same steps as i stated before.

Key to note is the steps i mentioned before will add the DLL reference to your dev-environment, where as the step i just stated will add the reference to your specific project and it should open up the available namespaces and allow you to include the ones you want into your project.

This post has been edited by woodjom: 29 May 2009 - 07:07 AM

Was This Post Helpful? 0
  • +
  • -

#5 the_hangman  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 13
  • View blog
  • Posts: 602
  • Joined: 18-January 06

Re: VB.net / C++ Interoperability

Posted 29 May 2009 - 10:52 AM

I feel silly for not being able to figure this out...

I can't seem to get the DLL going. When I add the reference to the VB project I get: "A reference to (fileName) could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM reference"

I'm sure I'm missing something when compiling the DLL

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#6 T3hC13h  Icon User is offline

  • D.I.C Regular

Reputation: 65
  • View blog
  • Posts: 337
  • Joined: 05-February 08

Re: VB.net / C++ Interoperability

Posted 29 May 2009 - 11:02 AM

I was able to compile the attached files with VS2K8 Express and add a reference to my VB.Net project.

I had to add public ref to the class definition. I know very little about C++ and I was unable to get the overloaded constructor to work :(.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#7 woodjom  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 29
  • View blog
  • Posts: 549
  • Joined: 08-May 08

Re: VB.net / C++ Interoperability

Posted 29 May 2009 - 11:14 AM

View Postthe_hangman, on 29 May, 2009 - 11:52 AM, said:

I feel silly for not being able to figure this out...

I can't seem to get the DLL going. When I add the reference to the VB project I get: "A reference to (fileName) could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM reference"

I'm sure I'm missing something when compiling the DLL


make sure it is COM-visible.

Try this solution, read the whole bit and see if it is the same problem you are having: TechNet

Or see if any of these returns fix your problem from Google
http://www.google.co...amp;startPage=1

This post has been edited by woodjom: 29 May 2009 - 11:21 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1