Solved

VC++ Calling DLL function

Posted on 1997-12-19
8
732 Views
Last Modified: 2012-05-04
I want to write a vc++ program that can call external DLL functions. Does anyone know how to do that? Thanks in advance.
0
Comment
Question by:softyan
8 Comments
 
LVL 1

Expert Comment

by:quekky
ID: 1176756
do you have the header file and library of this dll?
if you have, just add the library to your project

0
 
LVL 1

Expert Comment

by:quekky
ID: 1176757
if not, you can use:-

HINSTANCE LoadLibrary(
  LPCTSTR lpLibFileName  // address of filename of executable module
);
 
FARPROC GetProcAddress(
  HMODULE hModule,  // handle to DLL module
  LPCSTR lpProcName  // name of function
);


if the dll is your own, you can create dependencies in VC

0
 

Author Comment

by:softyan
ID: 1176758
I do have the header file of the dll, but i don't have the library of this dll. I included the header file in my program, like the following:

#include <odbcinst.h>

but everytime i compile the program it give me this kind of error:

C:\MSDEV\INCLUDE\odbcinst.h(67) : error C2143: syntax error : missing '{' before '__stdcall'
C:\MSDEV\INCLUDE\odbcinst.h(67) : error C2146: syntax error : missing ')' before identifier 'hwndParent'
C:\MSDEV\INCLUDE\odbcinst.h(67) : error C2501: 'hwndParent' : missing decl-specifiers

i don't know what's going on about this header file, i checked it with other header file, but there are similar to each other!
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 1

Expert Comment

by:quekky
ID: 1176759
can you print line 60 to 70 of this header file here
0
 

Author Comment

by:softyan
ID: 1176760
Here is the header file, thanks in advance for helping me!

#ifndef WIN32
#define SQLGetPrivateProfileString   GetPrivateProfileString
#define SQLWritePrivateProfileString WritePrivateProfileString
#endif

// High level APIs
BOOL INSTAPI SQLInstallODBC          (HWND       hwndParent,
                                      LPCSTR     lpszInfFile,
                                                        LPCSTR     lpszSrcPath,
                                                        LPCSTR     lpszDrivers);

0
 
LVL 1

Expert Comment

by:quekky
ID: 1176761
try
#include <windows.h>
#include "odbcinst.h"
0
 

Expert Comment

by:XLogger
ID: 1176762
try this:

  extern "C" {
  #include "odbcinst.h"
  }

it helped me to resolve the same problem.
0
 

Accepted Solution

by:
yingchunli earned 100 total points
ID: 1176763
You might do it in the following way:

void (*PtrFunctionInDll)();
HINSTANCE hInstance;

hInstance=::LoadModule("yourDll.DLL");
PtrFunctionInDll=::GetProcAddress(hInstance, "functionInDll");


0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

803 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