Page 1 of 1

Calling DLL

Posted: Thu Aug 21, 2008 1:04 pm
by orange
hi
simple thinks first
i have a simple question about PureDispHelper which it's page in:
http://www.purebasic.fr/english/viewtopic.php?t=26744
and i am confused about the correct code.
i have an activex dll made by activestate perl development kit which it's function is to join two strings: it's main code is:
package joining;
sub joinwords
{
my $word1 = $_[0];
my $word2 = $_[1];
my $word3 = $word1.$word2;
return $word3;
}
;;;;;;;;;;;;;;;;;;
the successful visual basic 6.0 code to invoke such a dll is:
Dim objjoin
Dim result
Set objjoin = CreateObject("joining.Library")
word1$ = "first"
word2$ = "second"
result = objjoin.joinwords(word1$, word2$)

MsgBox (result)

Set objjoin = Nothing
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
in purebasic:
XIncludeFile "DispHelper_Include.pb"
dhToggleExceptions(#True)
Define.l tojoin
tojoin = dhCreateObject("joining.Library")

If tojoin
dhPutValue(... i am confused here :?:
dhCallMethod(... confused :?:
dhGetValue(... confused :?:
MessageRequester(result.s)
;;;;;;;;;;;;;;;;;;;;;;

can someone please give me an answer for the absolute beginner . how to supply the two words "first" and "second" from purebasic to that joining.dll and return the result as the string "firstsecond".
thanks

Posted: Thu Aug 21, 2008 1:21 pm
by idle
a$ + b$ or is that to simple?

Posted: Thu Aug 21, 2008 3:41 pm
by orange
idle wrote:a$ + b$ or is that to simple?
i am asking about how to pass the two variables to:
dhPutValue(...
dhCallMethod(...
dhGetValue(...
so to call the dll and get the answer from it


thanks

Posted: Thu Aug 21, 2008 3:49 pm
by srod
Try :

Code: Select all

Define retVal
dhGetValue("%T", @retval, tojoin, "joinwords(%T, %T)", @word1$, @word2$)
If retVal
  word3$ = PeekS(retVal)
EndIf
You may have to tinker with this and don't forget to use dhFreeString(retVal) at some point.

Posted: Thu Aug 21, 2008 3:51 pm
by gnozal
Maybe something like

Code: Select all

dhGetValue("%s", @Result.s, tojoin, "joinwords(%s,%s)", @word1$, @word2$)

This works for me

Posted: Thu Aug 21, 2008 4:15 pm
by glops
;I found parts of the puzzle in the forums and it is ok for me

Code: Select all

Procedure.s ReadBSTR(bstr) ; by Fr34k 
  length = WideCharToMultiByte_(#CP_ACP, 0, bstr, -1, 0, 0, 0, 0) 
  Text$ = Space(length) 
  WideCharToMultiByte_(#CP_ACP, 0, bstr, -1, @Text$, length, 0, 0)    
  ProcedureReturn Text$ 
EndProcedure 

;    Result = AllocateMemory(1024)
 dhGetValue("%B", @Result, obj, "object_method_name(%d, %d)", 1, 2)
 ;Debug PeekS(Result);OK but only 1 char
 ;Debug Result 
 Debug ReadBSTR(Result)
assuming the method returns a BSTR with 2 input parameters
but I don't have your DLL so I cannot help you more

Posted: Thu Aug 21, 2008 4:59 pm
by orange
to 'srod' thanks it is working fine :

Code: Select all

XIncludeFile "DispHelper_Include.pb" 
dhToggleExceptions(#True) 
Define.l tojoin 
tojoin = dhCreateObject("joining.Library") 
word1$="first"
word2$="second"

If tojoin 


Define retVal 
dhGetValue("%T", @retval, tojoin, "joinwords(%T, %T)", @word1$, @word2$) 
If retVal 
  word3$ = PeekS(retVal) 
  MessageRequester("",word3$)
  
EndIf 
EndIf
dhFreeString(retVal)

but if i comment MessageRequester("",word3$) it will issue an error like this image:
http://link.imgshare.us/8kjMja

thanks gnozal , after i replace the above line by your line and replacing retVal by Result.s i have an error:
'Bad parameter type, number expected instead of string'

thanks 'glops' , i can't run your code, can you please test it using my dll i have uploaded it to:
http://rapidshare.com/files/139022384/joining.rar.html
together with source which was generated by perl Dev kit, and a setup.bat to copy it to windows\system32 then registering it, the dll contains perl 5.10 packaged by perl dev kit so it will run without perl installed
thanks

Posted: Thu Aug 21, 2008 5:03 pm
by Inf0Byt3
Why don't you try to:

Code: Select all

CoInitialize_(0) 
Before the messagerequester? :)

Posted: Thu Aug 21, 2008 5:06 pm
by srod
No, add

Code: Select all

dhInitializeImp()
to your code after

Code: Select all

XIncludeFile "DispHelper_Include.pb" 
this will call CoInitialize_() and ensure the library is set up for ansi/unicode etc.