Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

Calling dll function Please help!!!


4 replies to this topic

Dyerald

Dyerald
  • Members
  • 43 posts

Posted 19 November 2001 - 10:01

Hi,

I'm using ISDev7.01 and I have a standard project that calls a dll function that check the registration number on the CustomerInformation dialog. First I define the dll on the binary table on the Direct editor like this:

Name = REGNUM
ISBuildSourcePath = D:\ProjFiles\VoxtronCTI\regnum.dll

then I made a function like this:

prototype NUMBER regnum.CheckRegNumExt2(BYREF STRING, BYREF STRING, BYREF NUMBER, BYREF NUMBER, BYREF NUMBER, BYREF STRING, BYREF NUMBER, BYREF NUMBER, BYREF NUMBER);
export prototype CheckRegistrationNo(HWND, STRING, STRING, STRING,STRING);  

function CheckRegistrationNo(hMSI, svRegNo1, svRegNo2, svRegNo3, svCompany)
STRING  szFileName;          
STRING  szRegNo, svPrd, szReturn;      
NUMBER  nReturn, nLines, nReg, nE1, nSentinel, nRegVersion, nRuntime;
POINTER pt1;
NUMBER nval;

begin
      
  szFileName = "D:\\ProjFiles\\VoxtronCTI\\regnum.dll";
if(UseDLL(szFileName) < 0) then    
       MessageBox("UseDLL fail", SEVERE);
        return ERROR_INSTALL_FAILURE;  
   else
MessageBox("UseDll succeeded", INFORMATION);    
   endif;  
           
  if ( StrLength(svRegNo3) != REQ_LENGTH1) then
    return FALSE;
   endif;
   pt1 = &nval;
   MsiGetProperty(hMSI,szProperty,svRetProp,pt1);

   svPrd = svRetProp;        
   szRegNo = svRegNo1 + "-" + svRegNo2 + "-" + svRegNo3;
   nReturn=CheckRegNumExt2(szRegNo,svPrd,nRuntime,nLines,nReg,svCompany,nE1,nSentinel,nRegVersion);

   SprintfBox(INFORMATION, "return", "%d", nReturn);

if(nReturn = -1) then
MessageBox("This registration number is for Windows 95 only.",INFORMATION);
return FALSE;
elseif(nReturn = -2) then
MessageBox("This registration number is for Windows NT only.",INFORMATION);
return FALSE;
elseif(nReturn = -0) then
MessageBox("Invalid registration number!",INFORMATION);    
return FALSE;
elseif(nReturn = -3) then
MessageBox("Error in registration information. Check the registration number and company name.",INFORMATION);
return FALSE;
elseif(nReturn = -5) then
MessageBox("Registration number is valid only for an earlier version of Telebutler!",INFORMATION);
return FALSE;
endif;
  UnUseDLL(szFileName);
end;    

The UseDll works fine but when I run my project I encounter an unhandled exception error:
Error: 0x80040703
Description : Failed to find dll function regnum.CheckRegNumExt2

and then my project was aborted. Why is this happened? Any idea?? Does anybody know how to call a dll function other than this method??? What am I going to do?? Please I really need to make this work as soon as possible.

In addtion the dll I am using was a C programmed dll and i only have the dll file because the dll was programmed by another person and the function declaration of the dll was like this:

int CheckRegNumExt2(char *RegNum,char *app_name,int *runtime,int *lines,int *registered,char *name, int *digital, int *sentinel, int *version);

Please I realy need help. Anybody has an idea on how to call this function???

Thanks in advance,
Dyerald

(Edited by Dyerald at 9:09 am on Nov. 19, 2001)


mdoggett

mdoggett
  • Members
  • 11 posts

Posted 21 November 2001 - 18:24

Here are 2 things to Try

1: In the C DLL file before the return type int add the code "__declspec( dllexport )". Therefore the function should read "__declspec( dllexport ) int CheckRegNumExt2(char *RegNum,char *app_name,int *runtime,int *lines,int *registered,char *name, int *digital, int *sentinel, int *version); " This will ensure that this function is exported from the DLL.

2:  Change the Prototype in Developer so that instead of reading

prototype NUMBER regnum.CheckRegNumExt2(BYREF STRING, BYREF STRING, BYREF NUMBER, BYREF NUMBER, BYREF NUMBER, BYREF STRING, BYREF NUMBER, BYREF NUMBER, BYREF NUMBER);

It reads

prototype cdecl NUMBER regnum.CheckRegNumExt2(BYREF STRING, BYREF STRING, BYREF NUMBER, BYREF NUMBER, BYREF NUMBER, BYREF STRING, BYREF NUMBER, BYREF NUMBER, BYREF NUMBER);

This tells developer that the function being imported is from a C DLL and it will handle the name Mangling correctly.

If you make both of these alterations then it should work fine. Let me know how you get on.


mahmoud

mahmoud
  • Members
  • 2 posts

Posted 13 January 2002 - 17:08

Hello all;
I faced with exactly same problem.
I wrote dll and Installshied script my self.
I done Dyerald instruction but still get the same error.
Please help me.

Dyerald

Dyerald
  • Members
  • 43 posts

Posted 14 January 2002 - 04:55

Hi,

Thanks Mr. Mdoggett for your advices. Here's what I've done on my problem to make it work... Since the dll function that I was calling was written in C and I only got the regnum.dll itself. I made a dll wrpper (checkregnumber.dll) that calls regnum.dll with this declaration:  

extern "C" DllExport int CheckRegNumber(char *serial,char *prd,int *runtime,int *nLines,int *bReg,char *name, int *nE1, int *nSentinel, int *nRegVersion);

Then on the checkregnumber.def file I wrote CheckRegNumber @1 on EXPORTS.

Here's the prototype on my  setup.rul just like Mr. Mdoggett advice...

prototype cdecl checkregnum.CheckRegNumber(BYREF STRING, BYREF STRING, BYREF NUMBER, BYREF NUMBER, BYREF NUMBER, BYREF STRING, BYREF NUMBER, BYREF NUMBER, BYREF NUMBER);

and calls the function like this...
UseDLL(SUPPORTDIR^"checkregnumber.dll");
nRetVal = CheckRegNumber(szRegNo,szProduct,nRuntime,nLines,nReg,szCompany,nE1,nSentinel,nRegVersion)
;

UnUseDLL(SUPPORTDIR^"checkregnumber.dll");

Hope it helps  =) Have a nice day =)

Dyerald



mahmoud

mahmoud
  • Members
  • 2 posts

Posted 14 January 2002 - 05:39

Hi,
and I,ve done this code that solved my problem.
extern "C" int __declspec(dllexport) foo(...)
Thanks to all.