Solved

VC++ Calling DLL function

Posted on 1997-12-19
8
729 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
 
LVL 1

Expert Comment

by:quekky
ID: 1176759
can you print line 60 to 70 of this header file here
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

743 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