|
Oh, that's so stupid, sorry. I meant C++ haha. Should be the same thing though, thank you a lot! I had never seen that guide before.
![]() |
static cell AMX_NATIVE_CALL MsgBox(AMX *amx, cell *params)
{
cell *cstr;
char *text, *caption;
amx_GetAddr(amx, params[1], &cstr);
amx_GetString(text, cstr, 0, UNLIMITED);
amx_GetAddr(amx, params[2], &cstr);
amx_GetString(caption, cstr, 0, UNLIMITED);
MessageBoxW(NULL, LPCWSTR(text), LPCWSTR(caption), MB_OK);
return 1;
}
char* text = ""
|
Код:
static cell AMX_NATIVE_CALL MsgBox(AMX *amx, cell *params)
{
cell *cstr;
char *text, *caption;
amx_GetAddr(amx, params[1], &cstr);
amx_GetString(text, cstr, 0, UNLIMITED);
amx_GetAddr(amx, params[2], &cstr);
amx_GetString(caption, cstr, 0, UNLIMITED);
MessageBoxW(NULL, LPCWSTR(text), LPCWSTR(caption), MB_OK);
return 1;
}
When I use the command in the server it gives me this window: EDIT: Oh, changed, so the variables are initialized, now instead I get Japanese text. :S |
cell AMX_NATIVE_CALL MsgBox(AMX *amx, cell *params)
{
cell *addr;
char *text, *caption;
int size[2];
amx_GetAddr(amx, params[1], &addr);
amx_StrLen(addr, &size[0]);
if(size[0])
{
size[0]++;
text = new char[ size[0] ];
amx_GetString(text, addr, 0, size[0]);
amx_GetAddr(amx, params[2], &addr);
amx_StrLen(addr, &size[1]);
if(size[1])
{
size[1]++;
caption = new char[ size[1] ];
amx_GetString(caption, addr, 0, size[1]);
MessageBoxW(NULL, LPCWSTR(text), LPCWSTR(caption), MB_OK);
delete[] text;
delete[] caption;
return 1;
}
delete[] text;
}
return 0;
}
|
You have to allocate memory if you're going to use a char pointer! You could just declare a simple char array instead, if you dont know anything about memory allocation.
Edit: Also, NEVER use "UNLIMITED" for a size parameter again - thats a good way to cause a buffer overflow. |
|
Here you can give this a try (Its a little sloppy and rushed):
Код:
cell AMX_NATIVE_CALL MsgBox(AMX *amx, cell *params)
{
cell *addr;
char *text, *caption;
int size[2];
amx_GetAddr(amx, params[1], &addr);
amx_StrLen(addr, &size[0]);
if(size[0])
{
size[0]++;
text = new char[ size[0] ];
amx_GetString(text, addr, 0, size[0]);
amx_GetAddr(amx, params[2], &addr);
amx_StrLen(addr, &size[1]);
if(size[1])
{
size[1]++;
caption = new char[ size[1] ];
amx_GetString(caption, addr, 0, size[1]);
MessageBoxW(NULL, LPCWSTR(text), LPCWSTR(caption), MB_OK);
delete[] text;
delete[] caption;
return 1;
}
delete[] text;
}
return 0;
}
|