Hello World DLL using Microsoft C++ compiler

Discussion in 'C++' started by cybose, Oct 19, 2006.

  1. cybose

    cybose Guest

    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
    cybose, Oct 19, 2006
    #1
    1. Advertising

  2. cybose

    mlimber Guest

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

    Cheers! --M
    mlimber, Oct 19, 2006
    #2
    1. Advertising

  3. cybose

    Moonlit Guest

    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" <> wrote in message
    news:...
    > 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
    >
    Moonlit, Oct 19, 2006
    #3
  4. * 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?
    Alf P. Steinbach, Oct 19, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vijay
    Replies:
    8
    Views:
    701
  2. Fei Liu
    Replies:
    9
    Views:
    440
  3. Roy
    Replies:
    6
    Views:
    600
    Roedy Green
    Jan 7, 2008
  4. Thufir
    Replies:
    6
    Views:
    118
    Thufir
    Mar 19, 2008
  5. Larry
    Replies:
    27
    Views:
    424
    Michele Dondi
    Jan 25, 2005
Loading...

Share This Page