BStr with PureDispHelper
- Stefan Schnell
- User
- Posts: 85
- Joined: Wed May 07, 2003 2:53 pm
- Location: Germany - Oberirsen
- Contact:
BStr with PureDispHelper
Hello community,
I want to use the library PureDispHelper and one of the functions need a BStr as argument. Does anybody knows how I can define a BStr variable and give them to a PureDispHelper function?
In the examples I found nothing.
Thanks for tips.
Cheers
Stefan
I want to use the library PureDispHelper and one of the functions need a BStr as argument. Does anybody knows how I can define a BStr variable and give them to a PureDispHelper function?
In the examples I found nothing.
Thanks for tips.
Cheers
Stefan
Use the unicode type, should work
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: BStr with PureDispHelper
I have not used PureDispHelper but here is a link to some ideas that may help:Stefan Schnell wrote:Hello community,
I want to use the library PureDispHelper and one of the functions need a BStr as argument. Does anybody knows how I can define a BStr variable and give them to a PureDispHelper function?
In the examples I found nothing.
Thanks for tips.
Cheers
Stefan
Talking about PureDispHelper, I'm trying to put Date values in some cells of an Excel document... the argument in the function is %D ( Date ) and the parameter must be passed ByRef . Which type of variable should I use with PureBasic ? I tried a string, but it doesn't work. Any hints ? Thanks.

Code: Select all
dhPutValue(COMObject,"Cells(%d, %d).Value = %D",1,1,@...)
freak has published the following code to convert a PureBASIC string into BSTR format on page 11 of his excellent COM tutorial (http://freak.purearea.net/help/COMTutorial.pdf)Stefan Schnell wrote: Does anybody knows how I can define a BStr variable and give them to a PureDispHelper function?
Code: Select all
Procedure.l MakeBSTR(String.s)
Protected Result = 0
CompilerIf #PB_Compiler_Unicode
Result = SysAllocString_(@String)
CompilerElse
Protected *Buffer = AllocateMemory(Len(String)*2 + 2)
If *Buffer
PokeS(*Buffer, String, -1, #PB_Unicode)
Result = SysAllocString_(*Buffer)
FreeMemory(*Buffer)
EndIf
CompilerEndIf
ProcedureReturn Result
EndProcedure
Code: Select all
If dhCallMethod(*YourObject, YourFunction(%B), MakeBSTR(YourString)) = #S_OK
...
End If
Take a look into mk-soft's and ts-soft's VariantHelper_Include.pb. They have declared lots of macros to help in conversions. This one converts a PB date into a double value which you can insert into Excel:Seldon wrote:Talking about PureDispHelper, I'm trying to put Date values in some cells of an Excel document... the argument in the function is %D ( Date ) and the parameter must be passed ByRef . Which type of variable should I use with PureBasic ? I tried a string, but it doesn't work. Any hints ? Thanks.![]()
Code: Select all
Procedure.d T_DATE(pbDate) ; Result Date from PB-Date
Protected date.d
date = pbDate / 86400.0 + 25569.0
ProcedureReturn date
EndProcedure
Code: Select all
EnableExplicit
Define.D CurrentDate
Define.L ExcelApp
Define.L Workbook
CurrentDate = Date() / 86400.0 + 25569.0
dhToggleExceptions(#True)
ExcelApp = dhCreateObject("Excel.Application")
If ExcelApp
dhPutValue(ExcelApp, ".Visible = %b", #True)
dhGetValue("%o", @Workbook, ExcelApp, ".Workbooks.Add")
dhPutValue(ExcelApp, "Cells(%d, %d).Value = %D", 1, 1, @CurrentDate)
MessageRequester("Date Insertion into Excel", "Click OK to close Excel")
dhCallMethod(ExcelApp, ".Quit")
dhReleaseObject(Workbook) : Workbook = 0
dhReleaseObject(ExcelApp) : ExcelApp = 0
Else
MessageRequester("PureDispHelper-ExcelDemo", "Couldn't create Excel-Object")
EndIf
Last edited by Shardik on Tue Mar 18, 2008 6:28 pm, edited 2 times in total.
- Fluid Byte
- Addict
- Posts: 2336
- Joined: Fri Jul 21, 2006 4:41 am
- Location: Berlin, Germany
- Stefan Schnell
- User
- Posts: 85
- Joined: Wed May 07, 2003 2:53 pm
- Location: Germany - Oberirsen
- Contact: