473,729 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
+ 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 2930
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\Visua l 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\Visua l 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\Visua l 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(lin e);
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
2593
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 rewriting other applications over to VB.net. My application has now been targeted with coming over, but management does not want to incur a rewrite timeline. Since we have a standard vb.net framework in place, their thoughts are to try and take the...
7
2758
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 emailed support, and the reply was: "We understand your concerns in this matter. We would like to inform you that at this moment we do not have any plan or information if there will be replacements for the discontinued exams." Does anybody...
6
2787
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 in order to call my c# modules from within c++? From what I understand, I need to convert my c++ code from unmanaged to managed using the /clr switch (IJW). Is this correct? Are there any other considerations I need to be aware of? Ben
10
2590
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 System::Threading::Thread::CurrentThread->ApartmentState = System::Threading::ApartmentState::STA; as the first statment of _tWinMain and also in the DllMain of my mixed mode assemblies.
4
1362
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? I want to know this because there is client/server application that i want to build. Now the server side has to be very fast in processing request and efficient in all other server related issues. I searched on internet(including the google...
8
2317
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 types. The problem: I have a number of mixed-mode functions which I want reuse. These functions revolve around converting a CLR String to a C++ std::string or
14
2135
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 platforms. If Win32 applications and .NET application both will run on windows only, what's the advantages for the migration? Or maybe this type of migration is not common in practice?
2
1656
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 could help me out here, I'd really appreciate it. Iam a project trainee. I have to give an presentation over the topic, For engineering applications, whether VC++ 6.0 is more suitable
0
1472
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 is fine. However, after deployment, each request fails with "The specified module cound not found" exception. It turns out to be the Managed assembly is copied to someplace at runtime. In my machine, it is "C:\WINDOWS\Microsoft.NET\Framework...
0
8931
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8767
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9428
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
6722
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4536
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4799
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3246
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2701
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2171
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.