Sprintf / sscanf

Discussion forum about all things Gupta, OpenText and the community.
Jsfmllr
Germany
Posts: 69
Joined: 17 Nov 2019, 16:08
Location: Munich, Bavaria, Germany

Sprintf / sscanf

Post by Jsfmllr » 09 Sep 2011, 09:42

Hello ,

currently i am using CTD 112 and 151.
can i use the benefits in formatting, which are provided by sprintf / sscanf ?

TIA

Sepp

Jeff Luther

Re: Sprintf / sscanf

Post by Jeff Luther » 10 Sep 2011, 00:08

benefits in formatting -- ?? What and how do you want to format that you cannot do with SAL functions? Generally, I think those functions are too 'low' for TD, but I'd like to know what problem you are trying to solve. Letting us know that could be helpful in answering your question.

micsto
Germany
Posts: 986
Joined: 07 Mar 2017, 16:07
Location: Germany

Re: Sprintf / sscanf

Post by micsto » 12 Sep 2011, 07:39

Did you try VisStrExpand? Not as flexible as sprintf, but maybe it's sufficient.

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 3392
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: Sprintf / sscanf

Post by Dave Rabelink » 12 Sep 2011, 20:09

Hi Sepp,

You could use the standard c library, msvcrt.dll which holds many C functions, including sprintf.

http://msdn.microsoft.com/en-us/library ... 60%29.aspx

I just created a quick starting point for you which declares a sprintf variant.
I say a variant, because the sprintf function has optional arguments.

http://msdn.microsoft.com/en-us/library ... 60%29.aspx

So you have to implement for every kind of formatting a specific declaration in TD.
In the sample I have created a version with 2 optional parameters (a float and an integer).

To be able to have multiple versions of the same function, you have to set the export ordinal to the correct value.

I hope you have a working starting point using this sample:

https://samples.tdcommunity.net/index ... rch_mode=f
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

User avatar
markus.essmayr
Austria
Posts: 892
Joined: 06 Mar 2017, 06:07
Location: Austria

Re: Sprintf / sscanf

Post by markus.essmayr » 13 Sep 2011, 08:00

Hello,

I'd like to add some info here!
TD uses the __stdcall calling convention (= FAR PASCAL) to call external functions, but sprintf/sscanf use the __cdecl calling convention!

See this article to find out the differences:
http://whatilearned2day.wordpress.com/2 ... __stdcall/

In short, TD passes the arguments on the stack and the called function has to remove them.
But in case of sprintf/sscanf TD will pass the arguments on the stack but the function won't remove them.
So I think that a Stack Overflow will be the result!
Maybe you can try calling the sprintf in a loop to find out, if the app crashes.

I requested to add Calling Convention support to TD quite some time ago, but there's no solution yet.

Greetings,
Max
Markus Eßmayr
teamdeveloper@t-mx.com

Jsfmllr
Germany
Posts: 69
Joined: 17 Nov 2019, 16:08
Location: Munich, Bavaria, Germany

Re: Sprintf / sscanf

Post by Jsfmllr » 13 Sep 2011, 14:45

Hello,
TNX fro reply

IIRC then the ?printf() and ?scanf() functions-family provides the benefit, that they accept a various number of arguments after the parameter with the format-string. the only condition is, that the number of parameter must fit to the format string.

printf( '%s', 'one)
sprintf( sTarget, 'here come %i %s of %s', 2, 'arguments' )
...

TIA

Sepp

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 1 guest