Possible to combine VB handle and C++ opengl?

Started by
4 comments, last by bzroom 20 years, 5 months ago
I want to create a model editor and I''m really not trying to mess with MFC as of now. I still need the nice GUI so I would like to create my program''s GUI in VB. When the program loads I will load a dll with my programs actual code and pass it the handle of my viewport. I will also have a function to take messages such as scrollbars and buttons. Thank you.
Advertisement
Yes, there is a way to do that. However, using a DLL in VB is not as simple as it is in C/C++. First, forget about using LoadLibrary() and GetProcAddress(). They simply don't exist in VB, as there aren't any pointers. You need to explicitly declare every DLL function you're going to use like this:
Public Declare Function MyDLLFunction Lib "mydll" Alias "RealNameOfMyDLLFunction"    (ByVal foo As Integer, ByVal bar As Long) As Boolean  
I suppose this would be fine if you're planning to run the whole program in the DLL, and only use VB for the front-end. You'll be needing three DLL functions: one for when the program initializes, one like the Win32 WndProc to which you can send messages, and one for when the program shuts down.

I'd still recommend that you use MFC. You can get to grips with it rather quickly, and it handles everything from views of your scene to file input/output to the user interface. Your control over the user interface and the way your program looks and feels is greatly increased in MFC. You can customise everything by simply overriding it's drawing function. With VB you're stuck with the default grey controls. However, this is more overhead when you're coding, and you probably won't need that level of control. Just an option to explore...

Insert [CENSORED] here.

[edited by - iNsAn1tY on November 16, 2003 7:48:45 AM]
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]
You can substitute Long datatype for pointers in VB5 and 6.
However, you can't modify the data pointed by them directly, because you can't dereference a pointer in VB.
Use CopyMemory api to simulate dereferencing, and VarPtr intrinsic to get pointers to your own variables.

-Nik

EDIT: Note that i'm not recommending to use VB in these circumstances; I just pointed out that you can use "pointers" in vb

[edited by - Nik02 on November 16, 2003 8:18:28 AM]

Niko Suni

quote:Original post by iNsAn1tY
Yes, there is a way to do that. However, using a DLL in VB is not as simple as it is in C/C++.

[edited by - iNsAn1tY on November 16, 2003 7:48:45 AM]


I guess I forgot to mention I''m very advanced in VB, I have a VB programming job. I''m looking for that way in terms of setting up opengl to render from this vb created handle, instead of my window creating code I normaly use in c++.

Any tutorials?
quote:Original post by honayboyz
I guess I forgot to mention I'm very advanced in VB, I have a VB programming job. I'm looking for that way in terms of setting up opengl to render from this vb created handle, instead of my window creating code I normaly use in c++.
Sorry, I just assumed you were a noob Are you asking about setting up OpenGL in VB? Because that's quite trivial. You need the OpenGL type library for VB, which you can get here. This file also includes all the Win32 function declarations, so then you just set OpenGL up as you would in C/C++ (get a hDC, grab a pixel format, load the pixel format, get a hRC, etc). In fact, NeHe's tutorial #1 has been converted to VB (you can find that here).

quote:Original post by Nik02
You can substitute Long datatype for pointers in VB5 and 6.
However, you can't modify the data pointed by them directly, because you can't dereference a pointer in VB.
Use CopyMemory api to simulate dereferencing, and VarPtr intrinsic to get pointers to your own variables.
Ah yes, I forgot about VarPtr

Insert [CENSORED] here.

[edited by - iNsAn1tY on November 16, 2003 3:57:05 PM]
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]
Nah, I''d really like to keep all my opengl code in c++. I never bothered to learn the windows creation code I was using and often I just use a modified glut (so that the mainloop dosnt hold the thread) to create my window.

I''m hoping there is a line that is something like this:

glSetViewHandle(myhandle);

I know that is not right, but instead of passing the handle of the window I just created, I would pass it the handle that the vb app just passed into the dll.

I think you set a device context, which I think you get with a function sorta like GetContextFromHandle(myhandle);

Has anyone done this before? Is it even possible?

This topic is closed to new replies.

Advertisement