Solved

Calling proc (no params or ret val) why is call skipped?

Posted on 2000-02-27
3
273 Views
Last Modified: 2010-04-02
I defined a REALLY SIMPLE dll in Delphi 4 which houses 1 function that doesn't take paramters and doesn't return anything.  When I call it from VC++, the loadLibrary call works, and the getProcAddr also works (seems to return a non null value...), but VC++ seems to SKIP MY CALL to the actual dll procedure.  Perhaps I have the syntax of the call wrong?

---------------------- VC++ test code
// testdll1.cpp : Defines the entry point for the application.
//

#include "stdafx.h"

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
       // TODO: Place code here.

    HINSTANCE hDLL;
    FARPROC ProcAdd;

    hDLL = LoadLibrary("a1.dll");
    ProcAdd = GetProcAddress(hDLL,"ANDY0");
    if (ProcAdd == NULL) return 0;

    ProcAdd;    // THIS IS SKIPPED????

    return 0;
}
------------------------
0
Comment
Question by:abulka
  • 2
3 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 50 total points
Comment Utility
Try it like this instead:

typedef void (WINAPI * PFANDYO)(void);

{
  PFANDYO pfANDYO;
  HINSTANCE hDLL;

  hDLL = LoadLibrary("a1.dll");

  pfANDYO = (PFANDYO)GetProcAddress(hDLL, "ANDYO");

  pfANDYO();

  return 0;
}
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
The key difference there is the "()" after the function pointer.  That is the "fucntion call operator", telling the compiler to call the function.
0
 
LVL 32

Expert Comment

by:jhance
Comment Utility
>The key difference there is the "()"
>after the function pointer.  

Yes, I mean to to say that...

I also find it's helpful to declare the call properly.  This is especially useful when calling DLL functions with arguments.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now