[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Using MSVC++ 4.2 to create DLL for CALL_EXTERNAL
[posted and mailed]
richt@sbrc.umanitoba.ca (Richard Tyc) wrote in
<85i7ag$hda$1@canopus.cc.umanitoba.ca>:
>I am new to Windows development and am having some problems creating a
>very simple DLL within Microsoft Developer Studio to be called my IDL
>using CALL_EXTERNAL. I have been discussing the problem with RSI tech
>support and they supplied me with the following simple program to try
>within Microsoft Developer Studio (v. 4.2) which I cannot get to
>compile. They use MSVC++ 6.0 so they are unable to help further.
I'm using 6 now, but I'm pretty sure the following compiled under 5 if not
4.
I'm not sure what your problem might be but you might try my first test
effort, it's very simple and somewhat different to the routine you posted.
>I am building the DLL within MSVC++ as a new project workspace->dynamic
>-link library. I then add the library idl32.lib with :
I didn't add any extra libraries, just included windows.h. I created an
empty workspace and added two files, Test_DLL.cpp (the code) and
Test_DLL.def. The latter tells the compiler which functions you want
exported in the DLL (it also prevents the exported function names being
changed (aka 'decoration')). Make sure the files have been added in to the
project.
Test_DLL.cpp :
#include <windows.h>
// Function prototypes.
BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ulReason, LPVOID lpReserved);
long WINAPI TimesTwo(int argc, void* argv[]);
// Windows DLL entry point.
BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ulReason, LPVOID lpReserved)
{
return(TRUE);
}
// Function to multiply number by two.
// Number to multiply is passed in the first argument (float)
// Answer returned in second argument (float)
long WINAPI TimesTwo(int argc, void* argv[]){
//argc holds number of parameters passed
//argv is array of pointers to passed parameters, i.e.
//argv[0]=pointer to first arg, argv[1] pointer to second, etc
//Define two pointers to floats
float *multiply_me, *answer;
multiply_me=(float *)argv[0];
answer=(float *)argv[1];
*answer = (*multiply_me) * 2.0;
return(0L); //Return zero if all okay
}
Test_DLL.def:
LIBRARY Test_DLL
DESCRIPTION 'DLL for use with IDL'
EXPORTS TimesTwo
The IDL code used to call the DLL:
pro test_dll
dll='D:\C++ projects\Test_DLL\Release\Test_DLL.dll'
a=FLOAT(10.21) ;Ensure we have floats to pass to DLL
b=FLOAT(1)
PRINT, a, b ;Before DLL
result = CALL_EXTERNAL (dll, 'TimesTwo', a, b)
PRINT, Result ;Should be zero
PRINT, a, b ;After DLL
end
And the output:
IDL> test_dll
10.2100 1.00000
0
10.2100 20.4200
Note that if you want to export more than one function in the DLL you list
them in the .def file as follows:
LIBRARY Test_DLL
DESCRIPTION 'DLL for use with IDL'
EXPORTS TimesTwo
TimesThree
TimesFour
Good Luck!
Justin