Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

using a DLL in VisualC++

Posted on 2003-03-31
3
Medium Priority
?
238 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
2 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

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

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

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…
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 goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

564 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