PDA

View Full Version : Using #declare and #declareapi access violations


tremers
04-26-2007, 05:39 PM
Hi,

I am a newbie and am attempting to call some c++ code in a dll.

The call to functions with no arguments works OK, however when I try and pass an int or long to the function PPL generates an access violation at 0x0.

I know that my functions without arguments are returning the correct values, so the dll is found and the declare functions are connecting to the code.

I have type cast the arguments TINT TLONG and return codes but to no avail.

Any ideas?

Also is there any planned support for Camera APIs or for Today Screen plugins?

Thanks,

Chris

kornalius
04-26-2007, 06:27 PM
PPL only supports 4 bytes integer, which is what you are using, great. Now is your c++ routine using stdcall or cdecl ?

#declare FunctionName DllName FunctionName INParamsCount OutParamsCount

You need to specify the amount of input and output parameters as well.

You can pass strings to the function as well.

tremers
04-26-2007, 11:19 PM
Sorry, I meant newbie at PPL.

The following are code snippets to illustrate my use of the language:

PPL:
#declareapi function0 "mydll.dll" function0 0 0
#declareapi function1 "mydll.dll" function1 0 1
#declareapi function2 "mydll.dll" function2 1 1
#declareapi function3 "mydll.dll" function3 1 1

... in WINMAIN

Type(iarg2$, TINT);
iarg2$=32;
arg3$"1234";

function0();// ok
ret1$ = function1();// ok return value is 42 shown while debugging
ret2$ = function2(iarg2$); // fail access violation address 0x0
ret3$ = function3(arg3$); // fail after message box displays "1234" as text

///////////////// C++ code snippet

//////mydll.h

#ifdef MYDLL_DLL_EXPORTS
#define MYDLL_DLL_API __declspec(dllexport)
#else
#define MYDLL_DLL_API __declspec(dllimport)
#endif

#ifdef __cplusplus
extern "C" {
#endif

MYDLL_DLL_API void function0(void);
MYDLL_DLL_API int function1(void);
MYDLL_DLL_API int function2(int);
MYDLL_DLL_API int function3(char *text);

#ifdef __cplusplus
}
#endif

///////// mydll.cpp

#include "mydll.h"


// This is an example of an exported function.
MYDLL_DLL_API void function0(void)
{
}

// This is an example of an exported function.
MYDLL_DLL_API int functio1(void)
{
return 42;
}


// This is an example of an exported function.
MYDLL_DLL_API int function2(int i)
{
return i+42;
}


int function3(char *text)
{
MessageBox(NULL,text,"function3 called",0); // this displays OK before the access violation
return 52;
}



/// end code examples.

The dll project was newly created and the only option was to remove precompiled headers.
I have tried both debug and release versions of the DLL. The DLL is automatically copied to the default path so that PPL can load it. Execution has only been tested on XP using Visual Studio 6.

Using type long in both PPL and C++ makes no difference. The real world problem is that the dll function will pass back a pointer, in that example the access viuolation was not at 0x0. But lets solve this example first.

Thanks for the fast reply,

Chris

tremers
04-26-2007, 11:51 PM
Oh, I tried __stdcall and nothing happened at all, return values not set and the Message box was not displayed. Using __cdecl resulted in the above behaviours.

Thanks again,

Chris

tremers
04-27-2007, 12:03 AM
Another update: I have also tried long/TLONG in the c++/ppl code although int is shown above.

PS the dll is compiled with Multithreaded DLL runtimes, etc:
Other flags are:
/nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "MYDLL_DLL_EXPORTS" /Fo"Release/" /Fd"Release/" /FD /c

Cheers,

Chris

kornalius
04-27-2007, 03:08 PM
Here is how I do it with the soon to be released SDK:

#define DLL_API __declspec(dllexport)

extern "C" DLL_API void ShutPPL ()
{
}

extern "C" DLL_API app *Run (char *s)
{
return _run(s, false);
}

Here are my project options (multithreaded, blend, 8 bytes alignment):

/nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "DLL_EXPORTS" /FR"Release/" /Fo"Release/" /Fd"Release/" /FD /c

tremers
04-30-2007, 03:13 AM
Alain,

thanks again for the quick reply and I may add a very interesting product.

I have changed all my compiler options to match yours - still no luck. I can see extensive use of the declare key word and when using registry.ppl entry points in the test application all is OK. I therefore assume it must be something in the dll I have created. The access violation is probable a problem within the stack, are there any stack overflow checking options that I should consider or any other link options for the dll?

In the mean time I can work around the problem for a project that I would like to use PPL with and will await the SDK which might solve the problem.

Thanks,

Chris

kornalius
04-30-2007, 02:04 PM
Try using the following calls:

ret2$ = function2(123); // fail access violation address 0x0
ret3$ = function3(&arg3$); // fail after message box displays "1234" as text

In function2, you should pass regular int values. The TINT you are creating is a pointer to an integer.

In function3, arg3$ should be ok, I don't know why it is not working.

Make sure you are not building your .dll in debug mode.