c++ - Vsscanf replacement for VS not working -
hey need used vsscanf due way legacy code did format comparing, microsoft decided didn't need include vsscanf stuck trying find implementation it. found http://www.flipcode.net/archives/vsscanf_for_win32.shtml 1 of first links , totally readable , understandable me, reason cant work.
not going include implementation of vsscanf because in link. copied , pasted , included file. simple code wanted run test , make sure got values access , copy on other places getting exception.
first code testing with:
int matches = 0; void** arglist = new void*[3]; matches = vsscanf("hello123test321", "hello%itest%i", (va_list)arglist); exception unhandled exception @ (location) in (project): 0xc0000005: access violation. occures when gets sscanf part of in lining.
(snippit source found @ link above) void *savedesp; _asm { mov savedesp, esp; mov esp, newstack; call sscanf; //this exception thrown mov esp, savedesp; mov result, eax; } i feel whatever doing silly need point out me. need make comparison, make sure there correct amount, , have structure values passed in back.
thanks
you allocate array of 3 pointers:
void** arglist = new void*[3]; but pointers not point anything. sscanf stored integers reads in memory pointers point to, random memory.
before calling vsscanf, need like:
void** arglist = new void*[2]; int* values = new int[2]; arglist[0]=(void *)values; arglist[1]=(void *)values+1; but think function never work. creates new stack parameters.
mov esp, newstack; call sscanf; but sscanf function use stack, call other functions or store registers on stack. allow stack must larger. or better, should use normal stack instead of creating 1 itself.
Comments
Post a Comment