Hello World DLL using Microsoft C++ compiler

C

cybose

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
 
M

mlimber

cybose said:
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/how-to-post.html#faq-5.9

Cheers! --M
 
M

Moonlit

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top