delphi : Access violation calling stdcall external C DLL?

Viewed 147

I've a Delphi project and I'm having a problem when calling a specific function from a external C DLL.

dll.h:

#ifndef _DLL_H_
#define _DLL_H_

#if BUILDING_DLL
#define DLLIMPORT __declspec(dllexport)
#else
#define DLLIMPORT __declspec(dllimport)
#endif
DLLIMPORT unsigned char *decrypted(char *datain,int len);
#endif

dllmain.c:

#include "dll.h"
#include <windows.h>
DLLIMPORT unsigned char * decrypted(char *textin ,int len)
{
    MessageBox(0,textin,"Hi",MB_ICONINFORMATION);
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
{
    switch(fdwReason)
    {
        case DLL_PROCESS_ATTACH:
        {
            break;
        }
        case DLL_PROCESS_DETACH:
        {
            break;
        }
        case DLL_THREAD_ATTACH:
        {
            break;
        }
        case DLL_THREAD_DETACH:
        {
            break;
        }
    }
    return TRUE;
} 

Delphi project:

...
const
  NomDLL = 'crpt.dll';
  function decrypted(datain : PAnsiChar ;len : integer) : PAnsiChar;   stdcall; external NomDLL;

text := 'xxxx';
decrypted(PAnsiChar(text),length(text));

end.

The decrypted function works perfectly without parameters?

0 Answers
Related