473,473 Members | 1,511 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

VC++ .NET 2002: Using native C++ DLLs in MC++ & Getting incomplete output

Hi all,
I copied a set of VC++ version 6 source code of
the 'cppdll'(2 projects) from a website and put the
cppdll.cpp, cppdll.def, cpp.h, (as the 1st project) and
test.cpp (as the 2nd project) into my Microsoft VC++ .NET
2002 - Windows XP Pro PC:
//----cppdll.cpp----
#include "cppdll.h"

//prevent function name from being mangled
extern "C"
int cube(int num) {
return num * num * num;
}
//-----cppdll.def----
EXPORTS
cube
//-----cpp.h------
/*
this header is not required for this dll
to compile; but is required for the app
that will use this dll
*/

#ifndef CPPDLL_H
#define CPPDLL_H

//computes the square of the number
//prevent the function name from being mangled
extern "C"
int cube(int num);

#endif //CPPDLL_H
//------test.cpp------
#include <iostream>

#include "cppdll.h"

using namespace std;

int main() {
int num;

cout << "enter any number: ";
cin >> num;

cout << "cube of number is "
<< cube(num) << endl;

return 0;
}
===============================================
I did 'Build' successfully, clicked '! Start without
debugging' and the console had 'enter any number'
appeared. I typed in a number on the console and
pressed 'Enter' key and the console screen just
vanished!!!??? I do not know what it is wrong with my
program. Please help and tell me (1) what I should change
in the 'Configuration Properties' for each of the
cppdll.cpp, cppdll.def, cppdll.h and test.cpp files, and
(2) whether it is possible to use the native C++ input to
get the cube of the input number in the MC++ framework by
using a native C++ DLL.
Thanks in advance,
Scott Chang
Nov 17 '05 #1
5 2911
Scott,

The console window disappears when your application finishes. To keep
your application from finishing, add the following lines to the end of
the main function (before "return 0;"):

string s;
cin >> s;

This will cause the application to wait until after you have entered
some text.

Good luck!

Bart Jacobs

Scott Chang wrote:
Hi all,
I copied a set of VC++ version 6 source code of
the 'cppdll'(2 projects) from a website and put the
cppdll.cpp, cppdll.def, cpp.h, (as the 1st project) and
test.cpp (as the 2nd project) into my Microsoft VC++ .NET
2002 - Windows XP Pro PC:
//----cppdll.cpp----
#include "cppdll.h"

//prevent function name from being mangled
extern "C"
int cube(int num) {
return num * num * num;
}
//-----cppdll.def----
EXPORTS
cube
//-----cpp.h------
/*
this header is not required for this dll
to compile; but is required for the app
that will use this dll
*/

#ifndef CPPDLL_H
#define CPPDLL_H

//computes the square of the number
//prevent the function name from being mangled
extern "C"
int cube(int num);

#endif //CPPDLL_H
//------test.cpp------
#include <iostream>

#include "cppdll.h"

using namespace std;

int main() {
int num;

cout << "enter any number: ";
cin >> num;

cout << "cube of number is "
<< cube(num) << endl;

return 0;
}
===============================================
I did 'Build' successfully, clicked '! Start without
debugging' and the console had 'enter any number'
appeared. I typed in a number on the console and
pressed 'Enter' key and the console screen just
vanished!!!??? I do not know what it is wrong with my
program. Please help and tell me (1) what I should change
in the 'Configuration Properties' for each of the
cppdll.cpp, cppdll.def, cppdll.h and test.cpp files, and
(2) whether it is possible to use the native C++ input to
get the cube of the input number in the MC++ framework by
using a native C++ DLL.
Thanks in advance,
Scott Chang


Nov 17 '05 #2
Thanks, Bart.

I added the two statements to my test.cpp as you said.
I did 'Build' on the new test.cpp and I got the following
error:
c:\Documents and Settings\Scott H. Chang\My
Documents\Visual Studio Projects\cppdll\test\test.cpp
(17): error C2679: binary '>>' : no operator found which
takes a right-hand operand of type 'std::string' (or
there is no acceptable conversion)

I do not know what to do next to correct this error.
Please help and advise again.

Thanks,
Scott Chang
-----Original Message-----
Scott,

The console window disappears when your application finishes. To keepyour application from finishing, add the following lines to the end ofthe main function (before "return 0;"):

string s;
cin >> s;

This will cause the application to wait until after you have enteredsome text.

Good luck!

Bart Jacobs

Scott Chang wrote:
Hi all,
I copied a set of VC++ version 6 source code of
the 'cppdll'(2 projects) from a website and put the
cppdll.cpp, cppdll.def, cpp.h, (as the 1st project) and test.cpp (as the 2nd project) into my Microsoft VC++ .NET 2002 - Windows XP Pro PC:
//----cppdll.cpp----
#include "cppdll.h"

//prevent function name from being mangled
extern "C"
int cube(int num) {
return num * num * num;
}
//-----cppdll.def----
EXPORTS
cube
//-----cpp.h------
/*
this header is not required for this dll
to compile; but is required for the app
that will use this dll
*/

#ifndef CPPDLL_H
#define CPPDLL_H

//computes the square of the number
//prevent the function name from being mangled
extern "C"
int cube(int num);

#endif //CPPDLL_H
//------test.cpp------
#include <iostream>

#include "cppdll.h"

using namespace std;

int main() {
int num;

cout << "enter any number: ";
cin >> num;

cout << "cube of number is "
<< cube(num) << endl;

return 0;
}
===============================================
I did 'Build' successfully, clicked '! Start without
debugging' and the console had 'enter any number'
appeared. I typed in a number on the console and
pressed 'Enter' key and the console screen just
vanished!!!??? I do not know what it is wrong with my
program. Please help and tell me (1) what I should change in the 'Configuration Properties' for each of the
cppdll.cpp, cppdll.def, cppdll.h and test.cpp files, and (2) whether it is possible to use the native C++ input to get the cube of the input number in the MC++ framework by using a native C++ DLL.
Thanks in advance,
Scott Chang


.

Nov 17 '05 #3
I'm sorry for that. Instead of what I suggested before, try the following:

char buffer[200];
fgets(buffer, 200, stdin);

Also add the following to the start of the file:

#include <stdio.h>

Happy coding!

Bart Jacobs

Nov 17 '05 #4
Thanks, Bart.

I followed your instructions and added your new 3 lines
of code to my test.cpp. Then I did 'Build' on the new
test.cpp. Two strange happened after I did 'Build':
1) If I clicked '! Start without Debug' or 'Start' under
the Debug menu, I got the following dialog box:
cppdll - Executable for Debugging Session
Please specify the name of the executable file to be
used for the debug session.
Executable file name:
--------------------
| |\/|
--------------------
(3 choices appear if I clicked the drop-down |\/| button):
(Internet Explorer)
(ActiveX Control Test Container)
(regsvr32)
URL where the project can be accessed (ATL Saver only):
--------------------
| |
--------------------

2) If I went to the debug folder of my C:\Documents and
Settings\Scott H. Chang\My Documents\Visual Studio
Project\cppdll\test\debug, and double clicked the
test.exe file. Then the console appeared with the "enter
any number" on the screen - if I typed in any number, the
console just vanished!!!???

I do not understand the problems 1) and 2). Please help
and give me new instructions to solve the problems.

THanks,
Scott Chang
-----Original Message-----
I'm sorry for that. Instead of what I suggested before, try the following:
char buffer[200];
fgets(buffer, 200, stdin);

Also add the following to the start of the file:

#include <stdio.h>

Happy coding!

Bart Jacobs

.

Nov 17 '05 #5
> 1) If I clicked '! Start without Debug' or 'Start' under
the Debug menu, I got the following dialog box:
cppdll - Executable for Debugging Session
Please specify the name of the executable file to be
used for the debug session.
You cannot run a DLL. You can only run an EXE. Set the EXE project as
the startup project.
2) If I went to the debug folder of my C:\Documents and
Settings\Scott H. Chang\My Documents\Visual Studio
Project\cppdll\test\debug, and double clicked the
test.exe file. Then the console appeared with the "enter
any number" on the screen - if I typed in any number, the
console just vanished!!!???


Sorry for that. I never use iostream myself. I have tested the following
solution:

int num;

cout << "enter any number: ";
string line;
getline(cin, line);
istringstream line_stream(line);
line_stream >> num;

cout << "cube of number is "
<< cube(num) << endl;

cin.get();

return 0;

You also need to include the following:

#include <iostream>
#include <string>
#include <sstream>

Nov 17 '05 #6

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

Similar topics

1
by: Bob | last post by:
I would appreciate any suggestions on handling the following... I currently have a VC++ MDI Application. The core pieces/products are all handled in separate dll's. Our shop has slowly been...
7
by: ultranet | last post by:
I have cruised around http://msdn.microsoft.com/visualc/ and the rest of the site, and i am not able to find a single C++ or VC++ certification exam that will be available after June 30, 2004. I...
6
by: Ben Terry | last post by:
Hello, I have a VS 2003.NET solution which consists of four c++ unmanaged legacy projects. I am adding a new project to the solution which will be in c#. What do I need to do to my c++ projects...
10
by: Adriano Coser | last post by:
Hello. I'm moving an application VC 2003 to VC 2005 Beta2. I need to set STA ApartmentState model so the drag & drop registration can work. I used to do...
4
by: batista | last post by:
Hello to all, I want to know that wat's the future of vc++.net? I mean is it going to remain there or not, and if does then wud there be big changes to it or they'll stick with the current one?...
8
by: Edward Diener | last post by:
By reuse, I mean a function in an assembly which is called in another assembly. By a mixed-mode function I mean a function whose signature has one or more CLR types and one or more non-CLR...
14
by: John | last post by:
My friend told me that his company will migrate the VC++ win32 applications to C++ .NET windows applications. I don't understand why since currently Microsoft only supports .NET on windows...
2
by: bhag | last post by:
hi all, I'm writing because I haven't been able to find enough information at the book stores and at the MS web site on some of my questions. Perhaps I'm asking the wrong questions, but if you...
0
by: Morgan Cheng | last post by:
I have one webservice written in MC++, which uses another native DLL deployed in %webservice_install_dir%\bin folder. The API invocation between MC++ and native C++ looks seamless. The compilation...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.