C Runtime Library & variable parameters
-
- Enthusiast
- Posts: 732
- Joined: Fri Jul 14, 2006 8:53 pm
- Location: Malta
- Contact:
C Runtime Library & variable parameters
I've recently seen a post (which I cant find again!) of an optimized FindString using the C runtime library (MSVCRT.DLL) and prototypes. First of all I want to thank the author(s) for such a splendid example. I adapted for using strchr and strrchr. And working thanks very much!
But
I tried to get sprintf to work.....without any luck
So I have 2 questions
1. Is it possible to make a macro/function in PB with a variable number of parameters ?
2. Is it possible to use the sprintf in the C Runtime library (or any similar functions which use variable number of parameters)
cheers
KingLestat
But
I tried to get sprintf to work.....without any luck
So I have 2 questions
1. Is it possible to make a macro/function in PB with a variable number of parameters ?
2. Is it possible to use the sprintf in the C Runtime library (or any similar functions which use variable number of parameters)
cheers
KingLestat
- netmaestro
- PureBasic Bullfrog
- Posts: 8433
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
http://www.purebasic.fr/english/viewtopic.php?t=24268I've recently seen a post (which I cant find again!) of an optimized FindString using the C runtime library (MSVCRT.DLL) and prototypes
BERESHEIT
-
- Enthusiast
- Posts: 732
- Joined: Fri Jul 14, 2006 8:53 pm
- Location: Malta
- Contact:
I don't know what you want to do. Just call sprintf?
Code: Select all
OpenLibrary(0, "msvcrt.dll")
sprintf = GetFunction(0, "sprintf")
CloseLibrary(0)
a = 5
n = @"A: %d"
buffer.s = Space(50)
CharsWritten = CallCFunctionFast(sprintf, buffer, n, a)
Debug buffer
Debug CharsWritten
Debug Len(buffer)
-
- Enthusiast
- Posts: 732
- Joined: Fri Jul 14, 2006 8:53 pm
- Location: Malta
- Contact:
antoher way :
Code: Select all
ImportC "msvcrt.lib"
sprintf(Buffer.s, Format.s, Arg1.l = 0, Arg2.l = 0, Arg3.l = 0, Arg4.l = 0) ; Write formatted data to a string.
EndImport
Result$ = Space(10)
If sprintf(Result$, "%d%d%d", 123, 456, 789)
Debug Result$
EndIf
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
- netmaestro
- PureBasic Bullfrog
- Posts: 8433
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Umm yes, I misread the import table thinking crt.dll was msvcrt.dll. But kernel32.dll is still always loaded even if it's closed.netmaestro wrote:@Trond: yours doesn't work because you closed the library too soon. (again) Your code will be a lot more reliable when you learn to leave libraries open until you're finished with them. Assuming they'll be available because you're under the impression that they're always loaded is a mistake.
Re: C Runtime Library & variable parameters
Code: Select all
EnableExplicit
Define lib.l, a.i, n.s, buffer.s, CharsWritten.i
lib = OpenLibrary(#PB_Any, "msvcrt.dll")
PrototypeC.i ProtoSprintf(Buffer.s, Format.s, Arg1.l = 0, Arg2.l = 0, Arg3.l = 0, Arg4.l = 0)
Global sprintf.ProtoSprintf = GetFunction(lib, "swprintf")
CloseLibrary(lib)
a = 5
n = "About: %d"
buffer = Space(50)
CharsWritten = sprintf(buffer, n, a)
Debug buffer
Debug CharsWritten
Debug Len(buffer)
Code tags added
17.06.2017
RSBasic
- Fluid Byte
- Addict
- Posts: 2336
- Joined: Fri Jul 21, 2006 4:41 am
- Location: Berlin, Germany
Re: C Runtime Library & variable parameters
I have to correct myself, THIS, is the worst case of necro-posting I have ever seen. 11 years, come the fuck on dude ....
And again no code-tags. Just wow ....
And again no code-tags. Just wow ....
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Re: C Runtime Library & variable parameters
@Fluid Byte: Dude... chill... It's his/her 5th post and most likely doesn't know better. No reason to be rude!
@Poplar: Maybe use the
@Poplar: Maybe use the
Code: Select all
-tag next time. Some people are easily triggered... :(
Et cetera is my worst enemy
- Fluid Byte
- Addict
- Posts: 2336
- Joined: Fri Jul 21, 2006 4:41 am
- Location: Berlin, Germany
Re: C Runtime Library & variable parameters
If it's his 5th or 5000th post is irrelevant, your argument is pointless. You don't necro-post 11 year old posts, period. Stop defending behavior like this.chi wrote:@Fluid Byte: Dude... chill... It's his/her 5th post and most likely doesn't know better. No reason to be rude!
chi wrote:@Poplar: Maybe use theCode: Select all
-tag next time. Some people are easily triggered... :([/quote] Triggered? Are you a stereotypical 14 year old meme kid on YouTube? Don't waste peoples time with this bullshit please.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Re: C Runtime Library & variable parameters
@Fluid Byte:
Whats up with you today? Take it down a notch and stop antagonizing people. If you continue acting like you're in kindergarden, I'll have to give you a time out.
Have a beer and relax a bit dude.
Whats up with you today? Take it down a notch and stop antagonizing people. If you continue acting like you're in kindergarden, I'll have to give you a time out.
Have a beer and relax a bit dude.
quidquid Latine dictum sit altum videtur