Page 1 of 1

Bug in Dll Creation ?!?

Posted: Mon Aug 04, 2003 2:15 pm
by ziggy
Hi !

I am playing around a bit with Dll creation and maybe found a bug...
There is a Programm called PGina take a look here to find out what
it is for : http://pgina.xpasystems.com/index.php

I am trying to make a lil Plugin for that Programm as a PBDll but the
Dll only gets one Character back from the Programm where is has to be a complete string...

Here my Example Code :
----
ProcedureCDLL UserLogin(user$, pass$, *pGinaInfo);
CreateFile(#1,"C:\pGina\Plugin SDK\debug.txt")
WriteString(user$)
WriteString(pass$)
EndProcedure
-----
With ProcedureDll the Programm runs into Pagefault.

The Function should have that format:
SAMPLEPLUGIN_API BOOL UserLogin(LPTSTR, LPTSTR, pGinaInfo *);

Did i do something wrong in my Dll or is there a Bug in PB ?
The Doku says the Dll has to use UniCode .. Does PB use UniCode or Ansi ? and how to change it

Greets
Georg

Posted: Mon Aug 04, 2003 6:44 pm
by Num3
Well if you examine the API line:

SAMPLEPLUGIN_API BOOL UserLogin(LPTSTR, LPTSTR, pGinaInfo *);

It says that UserLogin returns a BOOL value (true/false), so if you're getting 1 character back it means it's working!

Posted: Mon Aug 04, 2003 9:25 pm
by Paul
I took a quick look at their SDK for pGina and yes, it uses Unicode where as PB uses ANSI. Of course all is not lost, just write a little converter (Microsoft was nice enough to provide some API calls for this)

This is what I came up with using the example/tutorial in their SDK (and it seems to respond nicely using their "plugin_tester" application)

Code: Select all

;-Init Structure
;
Structure pGinaInfo 
  pathMSGina.l 
  pathPlugin.l 
  pathProfile.l 
  mapPaths.l 
  Username.l
  Password.l 
  homeDir.l
  isAdmin.l  
  disabled.l  
  authType.l 
  hUser.l 
  userGroups.l 
  userDescription.l 
  userFullName.l 
  allowPassChange.l  
  errorString.l  
  defaultDomain.l 
  Reserved3.l  
  Reserved4.l 
EndStructure
 
 
 
 
;-Unicode Ansi Converters
;
Procedure Ansi2Uni(ansi.s)
  unilen=Len(ansi)*2+1
  unicode=SysAllocStringLen_(0,unilen)
  MultiByteToWideChar_(#CP_ACP,0,ansi,Len(ansi)+1,unicode,unilen)
  result=unicode
  SysFreeString_(unicode)   
  ProcedureReturn result   
EndProcedure
 
 
Procedure Uni2Ansi(unicode)
  Shared ansi.s
  bstr=SysAllocString_(unicode)
  ansilen=SysStringLen_(bstr)+1
  ansi.s=Space(ansilen)
  WideCharToMultiByte_(#CP_ACP,0,bstr,-1,@ansi,Len(ansi),0,0)
  SysFreeString_(bstr)
  ProcedureReturn @ansi  
EndProcedure
 

 
 
 
 
;-Main DLL Functions
;
ProcedureCDLL UserLogin(User.s,Password.s,*GI.pGinaInfo)
  If PeekS(Uni2Ansi(*GI\Password))="mypassword"
    *GI\isAdmin=1
    *GI\allowPassChange=1     
    *GI\userDescription=Ansi2Uni("Sample Plugin User")
    *GI\userGroups= Ansi2Uni("Sample")
    Result=1
     
    Else
    *GI\errorString=Ansi2Uni("Password is incorrect")
  EndIf
  ProcedureReturn Result
EndProcedure
 
  
  
ProcedureCDLL ChangeUserPassword(User.s,OldPassword.s,NewPassword.s) 
  ProcedureReturn 1
EndProcedure
  
 
 
ProcedureCDLL AboutPlugin()
  about.s="This is a Sample Plugin for pGina"+Chr(13)+Chr(10)
  about+"created by Paul Leischow, August 4, 2003"
  ProcedureReturn Ansi2Uni(about)
EndProcedure
 
 
 
ProcedureCDLL ChangePluginSettings()
  MessageRequester("Settings","Hello There",0)
EndProcedure 
 
  
  
ProcedureCDLL LoginHook(*pGI.pGinaInfo) 
EndProcedure
 
 
 
ProcedureCDLL LogoutHook(*pGI.pGinaInfo)
EndProcedure 
 
 
 
ProcedureCDLL IsRequired()
  ProcedureReturn 0
EndProcedure

This should get you going I think?
:)