Calling DLL

Just starting out? Need help? Post your questions and find answers here.
orange
New User
New User
Posts: 3
Joined: Thu Aug 21, 2008 9:51 am

Calling DLL

Post 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
Last edited by orange on Thu Aug 21, 2008 1:58 pm, edited 2 times in total.
User avatar
idle
Always Here
Always Here
Posts: 5905
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Post by idle »

a$ + b$ or is that to simple?
orange
New User
New User
Posts: 3
Joined: Thu Aug 21, 2008 9:51 am

Post 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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Maybe something like

Code: Select all

dhGetValue("%s", @Result.s, tojoin, "joinwords(%s,%s)", @word1$, @word2$)
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
glops
User
User
Posts: 38
Joined: Wed Jan 16, 2008 12:53 pm
Location: France

This works for me

Post 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
orange
New User
New User
Posts: 3
Joined: Thu Aug 21, 2008 9:51 am

Post 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
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Why don't you try to:

Code: Select all

CoInitialize_(0) 
Before the messagerequester? :)
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
Post Reply