calling a DLL, using MS VC++

Discussion in 'C++' started by Suzanne Vogel, Jul 1, 2003.

  1. Hi,

    I'm trying to call a DLL that I created using Microsoft Visual C++, and
    ascertain that I created the DLL properly. I've never created a DLL
    before, and the Microsoft documentation does not help me:
    http://msdn.microsoft.com/library/d...ng_the_dllexport_and_dllimport_attributes.asp
    Also, if possible, I want to avoid using the Visual C++ wizard to create
    a DLL, because that creates several files and extra lines of code.

    Below is my test code. The first file creates a DLL with the function
    "printHello()". The second file, the "main" program, tries to call that
    function in the DLL. I believe the main program *could* find the DLL,
    and that there is merely something wrong with my C++ syntax: I
    remembered to put the DLL into the directory where the executable for
    the main program was to be created, and set the PATH variable to search
    the current "." directory.

    ** What is causing my DLL link error?

    Thanks,
    Suzanne

    ------------------------------------------
    #include <stdlib.h>
    #include <iostream>

    __declspec(dllexport) println(char* s);

    __declspec(dllexport) void printHello() {
    std::cout << "Hello world\n";
    }
    ------------------------------------------
    #include <stdlib.h>

    __declspec(dllimport) void printHello();

    int main(int argc, char** argv) {
    void (*f)() = &printHello;
    f(); // Link error!!!

    return EXIT_SUCCESS;
    }
     
    Suzanne Vogel, Jul 1, 2003
    #1
    1. Advertising

  2. "Suzanne Vogel" <> wrote...
    > I'm trying to call a DLL that I created using Microsoft Visual C++, and
    > ascertain that I created the DLL properly. [..]


    It's not your first day here, is it? Don't you already know
    that MS-specific questions are off-topic here? Please visit
    microsoft.public.vc.language.
     
    Victor Bazarov, Jul 1, 2003
    #2
    1. Advertising

  3. > It's not your first day here, is it? Don't you already know
    > that MS-specific questions are off-topic here? Please visit
    > microsoft.public.vc.language.


    Got it. Sorry.
     
    Suzanne Vogel, Jul 1, 2003
    #3
    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. Anushi
    Replies:
    5
    Views:
    8,768
  2. Krzysiek
    Replies:
    2
    Views:
    528
    Krzysiek
    Jul 5, 2004
  3. Giles Brown
    Replies:
    4
    Views:
    843
    Giles Brown
    Jul 30, 2003
  4. Capsule

    calling c# dll from c++ dll

    Capsule, Oct 18, 2005, in forum: C++
    Replies:
    3
    Views:
    963
    Victor Bazarov
    Oct 18, 2005
  5. H. Simpson
    Replies:
    4
    Views:
    281
    H. Simpson
    Aug 3, 2004
Loading...

Share This Page