?
Solved

using a DLL in VisualC++

Posted on 2003-03-31
3
Medium Priority
?
237 Views
Last Modified: 2010-04-02
Hello,

I have some trouble with calling a DLL in Visual C++. Please help me!
I've written a program in VisualC++ to call a DLL file. I came to the DLL file by compiling a Matlab file with the function mcc. When I write a simple DLL file (output=input) my C++ program works very well and gets a good link with the DLL. But when I change the DLL file a little bit(output = 3* input), my program gets no good link with the DLL file. It seems that the main function can't call the other subfunctions of my dll file(the functions that are extra created when I changed my DLL file to "output=3*input" and are needed to perform the multiplication)
Please, can you explain me what's wrong, what I have to change??
Is their something wrong with the settings of my program?
Could you give me a good example of such a program?
Is there maybe something wrong with the mcc compiler code?
The code I used was "mcc -W lib:libFLOPS -t -h -T link:lib libmmfile.mlib FLOPS".

This is a part of my C++ program:
void CDLLTESTDlg::OnStartdllbutton()
{
typedef mxArray*(* LPFNDLLFUNC1)(mxArray* input);
HINSTANCE hDLL; // Handle to DLL
LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer

hDLL = LoadLibrary("libFLOPS.dll");

if (hDLL != NULL)
{

lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,"mlfFLOPS");

if (!lpfnDllFunc1)
{
// handle the error
FreeLibrary(hDLL);
SetDlgItemText(IDC_RESULTDLLCALL,"ddl found, but no function");

}
else
{
// call the function
char szTemp[100];
mxArray *INPUT=NULL,
*OUTPUT=NULL;
INPUT=mxCreateScalarDouble(100);


OUTPUT=(*lpfnDllFunc1)(INPUT);

sprintf(szTemp,"%f",mxGetScalar(OUTPUT));


SetDlgItemText(IDC_RESULT,szTemp);
SetDlgItemText(IDC_RESULTDLLCALL,"ddl en functie gevonden");
FreeLibrary(hDLL);

}
}


}


Thanx for your support ,
kind regards,
Geert
0
Comment
Question by:Geert2003
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Accepted Solution

by:
ulretsam earned 100 total points
ID: 8240023
Your declaration of the function pointer and the attachment to the dll are correct. I think the way you try to call the function via the pointer is incorrect.

try
OUTPUT=lpfnDllFunc1(INPUT);
instead of
OUTPUT=(*lpfnDllFunc1)(INPUT);

good luck
ulretsam
0
 
LVL 9

Expert Comment

by:tinchos
ID: 9566509
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: ulretsam

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

777 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