Click here to Skip to main content
15,895,283 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Linking VB and VC Pin
benjnp3-Oct-05 23:35
benjnp3-Oct-05 23:35 
GeneralRe: Linking VB and VC Pin
Cedric Moonen3-Oct-05 23:51
Cedric Moonen3-Oct-05 23:51 
GeneralRe: Linking VB and VC Pin
benjnp4-Oct-05 0:11
benjnp4-Oct-05 0:11 
GeneralRe: Linking VB and VC Pin
benjnp4-Oct-05 0:43
benjnp4-Oct-05 0:43 
GeneralRe: Linking VB and VC Pin
Cedric Moonen4-Oct-05 0:58
Cedric Moonen4-Oct-05 0:58 
AnswerRe: Linking VB and VC Pin
Roger Stoltz4-Oct-05 2:19
Roger Stoltz4-Oct-05 2:19 
GeneralRe: Linking VB and VC Pin
benjnp4-Oct-05 6:52
benjnp4-Oct-05 6:52 
AnswerRe: Linking VB and VC Pin
Roger Stoltz4-Oct-05 12:56
Roger Stoltz4-Oct-05 12:56 
What I meant with "multiple exes" was one main exe, e.g. your VB app, and perhaps a few COM EXE servers. I wrote this as a possible technical solution in the sense that it can be done, but it might not be the best solution.
Using ShellExecute reminds me of the old days of MSDOS and this is really not a nice solution, in fact it's really bad.

I also wrote "multiple binaries" meaning one exe and one or more dlls, which would be a more suitable way for you to complete your task at hand.
A COM component could be a dll. If you create a COM component using the ATL wizard, you will end up with a dll that contains your object. An ActiveX control is in fact a dll, even if the extension is 'ocx'.

You are writing a lot about CString as if it was the core of your problem.
Forget about it! CString is a MFC C++ class and Visual Basic cannot handle it since it's VB and not C++! For string representation VB uses something called B-strings, aka BSTR.
VB can only handle types that can be respresented with a VARIANT data type.
I recommend that you read more about it in MSDN.

I still haven't understood what you mean by "the functionalities of the application" that you want to handle in VC++.
It seems to me like splitting the code in one VB part and one VC part creates more problems for you than necessary.

However, if splitting the code is one of the goals in the project I suggest you create an ActiveX control using MFC for the VC part.
Below is what it takes to get you started with an ActiveX control:
Run the "MFC ActiveX ControlWizard" from DevStudio, choose a suitable name for your control, e.g. 'Cool' and in step 2 of the wizard check the "Available in 'Insert Object' dialog" checkbox and click 'Finish'.
Bring up ClassWizard and select the 'Automation" tab and click 'Add Method'.
Here you are forced to use only data types that can be handled by VB.
Choose a suitable name for your method, e.g. 'Test' and a return type, e.g. BOOL. Give the method a parameter called 'Text' and select LPCTSTR as the data type and click 'OK'.

You have now created an ActiveX control with an interface function called 'Test' that can be called from VB. I will tell you how in a minute.

It would be nice to see when the 'Test' function gets called so bring up the implementation file for your control; the file that ends with *Ctl.cpp and find the wizard generated function Test.
You will find that it takes a LPCTSTR called 'Text' as argument.
Show a message box when this function is called with the string 'Text' inside the message box with following statement:
MessageBox( Text, "From control", MB_ICONINFORMATION );
Build the project and you will have an *.ocx file in your debug directory which is your ActiveX component.

Now for the VB part:
Fire up VB and create a new standard EXE project.
Press <ctrl+t> and select your new component from the list and click 'OK'.
Add an instance of your control in the same way you add other controls such as buttons from the control bar. You'll find an 'ocx' control in the control bar.
Add a button to the interface and double-click it to add a handler for the click event. Call the 'Test' method of your component like this:
Cool1.Test "It works!"
Run the project and click the button and you should see a message box with the message "It works!".

A word of caution:
This is only a scratch on the surface, there's still quite a learning curve to be taken but this should get you started. This might not be the best technical solution, but this is what I consider to be the easiest way for you based on how I've interpreted your skills and needs.
Now you can add methods to the interface of your control that suits your needs that can be called from VB and you can write "the functionality of the application" in VC++. The instance of your control class will live for as long as the VB-app lives, which means that your member variables will keep their values between calls.
What you do here is a small part of COM using dispatch interfaces.

--
Roger

-- modified at 19:34 Tuesday 4th October, 2005
Forgot instructions for adding the control to the VB form.
GeneralRe: Linking VB and VC Pin
benjnp4-Oct-05 15:03
benjnp4-Oct-05 15:03 
QuestionCatch c++ runtime library error Pin
JensB3-Oct-05 23:09
JensB3-Oct-05 23:09 
AnswerRe: Catch c++ runtime library error Pin
Prakash Nadar4-Oct-05 1:10
Prakash Nadar4-Oct-05 1:10 
GeneralRe: Catch c++ runtime library error Pin
JensB4-Oct-05 3:36
JensB4-Oct-05 3:36 
AnswerRe: Catch c++ runtime library error Pin
Tim Smith4-Oct-05 4:12
Tim Smith4-Oct-05 4:12 
Questioncustomize file dialogs Pin
Boder Coder3-Oct-05 22:02
Boder Coder3-Oct-05 22:02 
AnswerRe: customize file dialogs Pin
Lane Yu4-Oct-05 3:46
Lane Yu4-Oct-05 3:46 
QuestionListView and List Ctrl Example Pin
karmendra_js3-Oct-05 21:53
karmendra_js3-Oct-05 21:53 
AnswerRe: ListView and List Ctrl Example Pin
Prakash Nadar3-Oct-05 22:12
Prakash Nadar3-Oct-05 22:12 
QuestionRe: ListView and List Ctrl Example Pin
David Crow4-Oct-05 3:12
David Crow4-Oct-05 3:12 
QuestionProcess ID from Process Name Pin
ragavan3-Oct-05 20:00
ragavan3-Oct-05 20:00 
QuestionList Control Pin
karmendra_js3-Oct-05 19:49
karmendra_js3-Oct-05 19:49 
AnswerRe: List Control Pin
ThatsAlok3-Oct-05 19:53
ThatsAlok3-Oct-05 19:53 
QuestionExponents Pin
karnal3-Oct-05 19:42
karnal3-Oct-05 19:42 
AnswerRe: Exponents Pin
Jose Lamas Rios3-Oct-05 21:02
Jose Lamas Rios3-Oct-05 21:02 
AnswerRe: Exponents Pin
dima_kdl4-Oct-05 1:45
dima_kdl4-Oct-05 1:45 
Questionhow do i typecast a CString to TCHAR type? Pin
Anonymous3-Oct-05 19:30
Anonymous3-Oct-05 19:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.