471,831 Members | 1,019 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,831 software developers and data experts.

Hello World DLL using Microsoft C++ compiler

Can someone help me write a HelloWorld dll using Microsoft's C++
compiler. It was straightforward doing it on Cygwin/g++, but it seems
to be an entirely different story on the MS C++ ?

In the case of using g++ ...

1.HelloWorld.h
~~~~~~~~~~~~
extern "C"
void printHelloWorld();

2.HelloWorld.cpp
~~~~~~~~~~~~~
#include <iostream>
extern "C"
void printHelloWorld() {
std::cout << "Hello World" << std::endl;
}

3.TestHW.cpp
~~~~~~~~~~~
#include "HelloWorld.h"
int main() {
printHelloWorld();
}

Once I compile and link 2. into a dll, and link that alongwith 3,
everything works as expected.

How do I mimic this using Microsoft C++ ?

Thanks

Oct 19 '06 #1
3 6116
cybose wrote:
Can someone help me write a HelloWorld dll using Microsoft's C++
compiler. It was straightforward doing it on Cygwin/g++, but it seems
to be an entirely different story on the MS C++ ?

In the case of using g++ ...

1.HelloWorld.h
~~~~~~~~~~~~
extern "C"
void printHelloWorld();

2.HelloWorld.cpp
~~~~~~~~~~~~~
#include <iostream>
extern "C"
void printHelloWorld() {
std::cout << "Hello World" << std::endl;
}

3.TestHW.cpp
~~~~~~~~~~~
#include "HelloWorld.h"
int main() {
printHelloWorld();
}

Once I compile and link 2. into a dll, and link that alongwith 3,
everything works as expected.

How do I mimic this using Microsoft C++ ?
This is a platform-specific question and is off-topic here. For what is
on-topic and for some suggestions on other newsgroups you could try,
see this FAQ:

http://parashift.com/c++-faq-lite/ho...t.html#faq-5.9

Cheers! --M

Oct 19 '06 #2


Hi,

I do this from the top of my head so don't take it to litterally.

Why not put it in one program. Anyway if you want it in a DLL just create a
DLL with the 'create project' wizard.
After that you have to create the program itself. Create a project with the
'create project' wizard and select executable (don't know the exact name).
In your case you would probably go for a console app.

Now in the properties of the project goto 'link' . Additional dependecies
and add the import library created in the DLL project (this is NOT the DLL
itself but a file called <your dll project>.lib. Also make sure to either
add the whole path to it. Copy the dll to the debug or release directory of
you project.

Now you would be able to run your project (assuming it has the code you gave
below).

Regards, Ron AF Greve

http://moonlit.xs4all.nl

"cybose" <vt****@gmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
Can someone help me write a HelloWorld dll using Microsoft's C++
compiler. It was straightforward doing it on Cygwin/g++, but it seems
to be an entirely different story on the MS C++ ?

In the case of using g++ ...

1.HelloWorld.h
~~~~~~~~~~~~
extern "C"
void printHelloWorld();

2.HelloWorld.cpp
~~~~~~~~~~~~~
#include <iostream>
extern "C"
void printHelloWorld() {
std::cout << "Hello World" << std::endl;
}

3.TestHW.cpp
~~~~~~~~~~~
#include "HelloWorld.h"
int main() {
printHelloWorld();
}

Once I compile and link 2. into a dll, and link that alongwith 3,
everything works as expected.

How do I mimic this using Microsoft C++ ?

Thanks

Oct 19 '06 #3
* Moonlit:
[off-topic]
Read the FAQ about topicality before posting. This group is about the
C++ language. Don't post off-topic articles.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Oct 19 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Rahul Gandhi | last post: by
9 posts views Thread by Brian | last post: by
33 posts views Thread by ankursinha | last post: by
42 posts views Thread by Prashanth Badabagni | last post: by
26 posts views Thread by Santanu Chatterjee | last post: by
NeoPa
reply views Thread by NeoPa | last post: by
aboka
reply views Thread by aboka | last post: by

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.