Jump to content

Is creating dynamic length parm. in c/cpp possible?


tebloraf
 Share

Recommended Posts

Hello, I'm trying to create a lua au3 lib (e.g for automated tools-install) and encountered a problem:

Some dll functions return the needed info via referenced parameter, so I need to create a buffer first (char[]) in order to get the info. However, this is of static length and some registry/ini values I need to process are quite large (~16M).

I could just create a huge buffer but that would be somewhat stupid when ~99% of the times I'm just retrieving ~10 chars.

So here's the question: Is it possible to dynamically set the buffer length (possibly, is there a function that tells me how long the char[] needs to be in order to get all info stored?)

If the problem is somehow solvable in C or C++, I can use the solution, as the lua binding is created in cpp w/ some extern "C" {...} - parts.

Any help appreciated

Thanks in advance

tebloraf

PS: One of the programs I want to auto. is exceptionally clever: it stores all its info. in a single .ini file, most of it in a single hex value. Lately its size was almost 512M! So I'd need to get the whole string just to change a single byte and then write back the string. But that could be solved by directly parsing the file, the RegRead is the problem...

Link to comment
Share on other sites

In C++, char[] and char* are synonomous. [] is actualy an arithmetic operator for pointers. When char* c is 5, and you call c[0], c[0] is 5. If you call c[1], c[1] is 6.

By using char* as the parameter type, you will receive the same value, but you should be able to read it as a NULL terminated string. IE: a string with a length of 5 will have a NULL at c[5].

Link to comment
Share on other sites

In C++, char[] and char* are synonomous. ...

That's what I already know. But in the AutoItX example it is written like this:

char szText[1000];

AU3_StatusbarGetText("Untitled -", "", 2, szText, 1000);

MessageBox(NULL, szText, "Text:", MB_OK);

A Buffer of fixed size. The Problem is that I'd need to write something like 'char szText[16777216];' or even larger - and allocating 16M of mem (or even more) every time I want to get some Info is a bit slow and memory-consuming... And this doesn't even get the whole string if it is still longer!

I need to know if there is a function that gives me the size of whatever I want to get, so perhaps something like 'char szText[Au3_StatusbarGetTextLength("Untitled -", "", 2)];' would be possible.

Or an other solution...

tebloraf

Link to comment
Share on other sites

Eh, I'm not sure how to help then. I'd say that you would have to work with a large allocation and hope it is big enough. If you want to make sure you get it all, you could try 'char szText[0xFFFFFFFF]'.

Edit: Forgot to mention that you will just about eat all the RAM you have, but it would get it all.

Edited by Icekirby1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...