The 'Pawn Language' Forum

An embedded scripting language

 

Back To Forum Index
 
Some little errors, please help me :)
Posted On 2011-08-31 14:56 -- Subject: Some little errors, please help me :)

I'm making a C application with an empty windows interface that will be built with the code(Using the Dev-C++ IDE because Visual Studio's projects are more hard to understand).

I have implemented in the project some of the standard CompuPhase premade libraries:
- amxstring
- amxfloat
- amxfixed
- amxcore

They all work perfectly during the execution.
Then I created "amxwin" following the same scheme of the others amx libraries and reading the PAWN Implementer's guide. I have no compile errors, but when I include my own include file and I write some of the implemented functions, only the FIRST is executed, then the program ends.

Is there any solution?? If you want to see the code, ask below.
[GF]Sasino97
Posted On 2011-08-31 14:57 -- Subject: RE: Some little errors, please help me :)

I'm the guy who wrote the topic. I didn't understand that the textbox "Name:" was for my nickname.

- [GF]Sasino97
Boris Estudiez
Posted On 2011-09-01 09:23 -- Subject: RE: Some little errors, please help me :)

Have you registered native functions in the abtract machine ?

[GF]Sasino97
Posted On 2011-09-02 08:31 -- Subject: RE: Some little errors, please help me :)

I'll post my code:


sorry, IDK how to format the text in this forum and to put the "code" box

-------------------- amxwin.h: -------------------------

#include "windows.h" // For Windows API
#include "window.h" // For the global window instance (hwnd)
#include "amx.h" // For the pawn abstract machine functions


/**
MessageBox(const message[], icon=ICON_ICONWARNING, buttons=DIALOG_OK);
*/

static cell AMX_NATIVE_CALL n_MessageBox(AMX *amx, const cell *params)
{
cell* cptr;
char* text;
cptr = amx_Address(amx, params[1]);
amx_GetString(text, cptr, sizeof(TCHAR)>1, 256);
return MessageBox(hwnd, (LPSTR)text, (LPSTR)"WindowsApp", params[2] | params[3]);
}

/**
SetWindowText(const text[]);
*/

static cell AMX_NATIVE_CALL n_SetWindowText(AMX *amx, const cell *params)
{
cell* cptr;
char* text;
cptr = amx_Address(amx, params[1]);
amx_GetString(text, cptr, sizeof(TCHAR)>1, 256);

return SetWindowText(hwnd, (LPSTR)text);
}

/**
CreateMenu();
*/

static cell AMX_NATIVE_CALL n_CreateMenu(AMX *amx, const cell *params)
{
return (cell)CreateMenu();
}

/**
CreatePopupMenu();
*/

static cell AMX_NATIVE_CALL n_CreatePopupMenu(AMX *amx, const cell *params)
{
return (cell)CreatePopupMenu();
}

/**
IsKeyDown(keycode);
*/

static cell AMX_NATIVE_CALL n_IsKeyDown(AMX *amx, const cell *params)
{
if(GetAsyncKeyState(params[1]) != 0) return 1;
return 0;
}

/**
DrawText(const text[], x, y);
*/

/*static cell AMX_NATIVE_CALL n_DrawText(AMX *amx, const cell *params)
{
cell* cptr;
char* text;
cptr = amx_Address(amx, params[1]);
amx_GetString(text, cptr, sizeof(TCHAR)>1, 256);

RECT rect;
HDC hdc = GetDC(hwnd);
int iLength = 0;
iLength = wsprintf(text, text);
SetRect(&rect, params[2], params[3], params[2] + 34, params[3] + 34);
DrawText(hdc, text, iLength, &rect, 32);
return 0;
}*/

#if defined __cplusplus
extern "C"
#endif

const AMX_NATIVE_INFO windows_Natives[] =
{
{ "MessageBox", n_MessageBox },
{ "SetWindowText", n_SetWindowText },
{ "CreateMenu", n_CreateMenu },
{ "CreatePopupMenu", n_CreatePopupMenu },
{ "IsKeyDown", n_IsKeyDown },
//{ "DrawText", n_DrawText },
{ NULL, NULL }
};

int AMXEXPORT AMXAPI amx_WindowsInit(AMX *amx)
{
return amx_Register(amx, windows_Natives, -1);
}

int AMXEXPORT AMXAPI amx_WinCleanup(AMX *amx)
{
(void)amx;
return AMX_ERR_NONE;
}

----------------------------------------------------------

I solved the that problem, but now I have some others problems:

I created this script to test windows natives and string natives:

------------------------- script.p -----------------------

#include <string>
#include <windows>

main()
{
new a[256];
strformat(a, 256, true, "%s, %s, Click yes or no", "Ciao", "hello");
if(!strcmp("Hello", "Hello", false, cellmax))
{
SetWindowText("Test PAWN Window application");
if(MessageBox(a, ICON_ICONINFORMATION, DIALOG_YESNO) == BUTTONID_YES)
{
MessageBox("You clicked YES!", ICON_ICONINFORMATION, DIALOG_OK);
}
else
{
MessageBox("You clicked NO!", ICON_ICONINFORMATION, DIALOG_OK);
}

}
return 0;
}


----------------------- windows.inc -----------------------


When i start the app the MessageBox with the message appears correctly, if i click "No" a MessageBox with text "You clicked NO!" appears.
If i click "Yes" appears another MSGBOX with text "IatI!naiked", but it should appear "You clicked YES!".

Oh yes, and the include file:

----------------------------------------------------------

////////////////////////////////////////// EVENTS //////////////////////////////////////////
//forward Event_Draw(); // You can use Draw functions only during this event!

////////////////////////////////////////// MAIN //////////////////////////////////////////

native SetWindowText(const text[]); // The text in the window caption

////////////////////////////////////////// MESSAGE BOXES //////////////////////////////////////////

native MessageBox(const message[], icon, buttons); // Shows a basic windows Message Box

/* Message Box Icons + Sounds */

#define ICON_ICONERROR 16
#define ICON_ICONQUESTION 32
#define ICON_ICONWARNING 48
#define ICON_ICONINFORMATION 64
#define ICON_ICONMASK 240


/* Message Box Buttons (Notice: The button text is different between countries) */

#define DIALOG_OK 0 // Buttons: "OK"
#define DIALOG_ABORTRETRYIGNORE 2 // Buttons: "Abort" "Retry" "Ignore"
#define DIALOG_HELP 0x4000 // Buttons: "OK" "?" tohex = 16384
#define DIALOG_OKCANCEL 1 // Buttons: "OK" "Cancel"
#define DIALOG_RETRYCANCEL 5 // Buttons: "Retry" "Cancel"
#define DIALOG_YESNO 4 // Buttons: "Yes" "No"
#define DIALOG_YESNOCANCEL 3 // Buttons: "Yes" "No" "Cancel"
#define DIALOG_CANCELTRYCONTINUE 6 // Buttons: "Cancel" "Retry" "Continue" - Notice: Some old windows version don't support this dialog style

/* Message Box Return Codes - The function MessageBox returns the id of the pressed button: */
#define BUTTONID_OK 1
#define BUTTONID_CANCEL 2
#define BUTTONID_ABORT 3
#define BUTTONID_RETRY 4
#define BUTTONID_IGNORE 5
#define BUTTONID_YES 6
#define BUTTONID_NO 7
#define BUTTONID_CLOSE 8
#define BUTTONID_HELP 9
#define BUTTONID_CONTINUE 11

////////////////////////////////////////// KEYBOARD INPUT //////////////////////////////////////////

native IsKeyDown(vkey);

//Mouse
#define VK_LEFTBUTTON 0x01
#define VK_RIGHTBUTTON 0x02
#define VK_MIDBUTTON 0x04

//Keyboard
#define VK_CANCEL 0x03
#define VK_BACKSPACE 0x08
#define VK_TAB 0x09
#define VK_CLEAR 0x0C
#define VK_ENTER 0x0D
#define VK_SHIFT 0x10 //Any of the 2 shift keys
#define VK_LSHIFT 0xA0 //Left Shift Key
#define VK_RSHIFT 0xA1 //Right shift key
#define VK_CTRL 0x11 //Any of the 2 control keys
#define VK_LCTRL 0xA2 //Left control key
#define VK_RCTRL 0xA3 //Right control key
#define VK_ALT 0x12
#define VK_CAPSLOCK 0x14
#define VK_ESCAPE 0x1B
#define VK_SPACE 0x20
#define VK_LEFT 0x25
#define VK_UP 0x26
#define VK_RIGHT 0x27
#define VK_DOWN 0x28
#define VK_SELECT 0x29
#define VK_INSERT 0x2D
#define VK_DELETE 0x2E
#define VK_HELP 0x2F

//Keyboard Numbers
#define VK_KEYB0 0x30
#define VK_KEYB1 0x31
#define VK_KEYB2 0x32
#define VK_KEYB3 0x33
#define VK_KEYB4 0x34
#define VK_KEYB5 0x35
#define VK_KEYB6 0x36
#define VK_KEYB7 0x37
#define VK_KEYB8 0x38
#define VK_KEYB9 0x39

//Numpad
#define VK_NUMLOCK 0x90
#define VK_NUMPAD0 0x60
#define VK_NUMPAD1 0x61
#define VK_NUMPAD2 0x62
#define VK_NUMPAD3 0x63
#define VK_NUMPAD4 0x64
#define VK_NUMPAD5 0x65
#define VK_NUMPAD6 0x66
#define VK_NUMPAD7 0x67
#define VK_NUMPAD8 0x68
#define VK_NUMPAD9 0x69
#define VK_MULTIPLY 0x6A
#define VK_ADD 0x6B
#define VK_SEPARATOR 0x6C
#define VK_SUBTRACT 0x6D
#define VK_DECIMAL 0x6E
#define VK_DIVIDE 0x6F

//Function Keys
#define VK_F1 0x70
#define VK_F2 0x71
#define VK_F3 0x72
#define VK_F4 0x73
#define VK_F5 0x74
#define VK_F6 0x75
#define VK_F7 0x76
#define VK_F8 0x77
#define VK_F9 0x78
#define VK_F10 0x79
#define VK_F11 0x7A
#define VK_F12 0x7B
#define VK_F13 0x7C
#define VK_F14 0x7D
#define VK_F15 0x7E
#define VK_F16 0x7F
#define VK_F17 0x80
#define VK_F18 0x81
#define VK_F19 0x82
#define VK_F20 0x83
#define VK_F21 0x84
#define VK_F22 0x85
#define VK_F23 0x86
#define VK_F24 0x87

//Letters
#define VK_A 0x41
#define VK_B 0x42
#define VK_C 0x43
#define VK_D 0x44
#define VK_E 0x45
#define VK_F 0x46
#define VK_G 0x47
#define VK_H 0x48
#define VK_I 0x49
#define VK_J 0x4A
#define VK_K 0x4B
#define VK_L 0x4C
#define VK_M 0x4D
#define VK_N 0x4E
#define VK_O 0x4F
#define VK_P 0x50
#define VK_Q 0x51
#define VK_R 0x52
#define VK_S 0x53
#define VK_T 0x54
#define VK_U 0x55
#define VK_V 0x56
#define VK_W 0x57
#define VK_X 0x58
#define VK_Y 0x59
#define VK_Z 0x5A

////////////////////////////////////////// DRAWING //////////////////////////////////////////

//native DrawText(const text[], x, y);

////////////////////////////////////////// MENUS //////////////////////////////////////////

native CreateMenu();
native CreatePopupMenu();
-----------------------------------------------------------
Boris Estudiez
Posted On 2011-09-03 13:20 -- Subject: RE: Some little errors, please help me :)

Hi,

Instead of:

static cell AMX_NATIVE_CALL n_MessageBox(AMX *amx, const cell *params)
{
cell* cptr;
char* text;
cptr = amx_Address(amx, params[1]);
amx_GetString(text, cptr, sizeof(TCHAR)>1, 256);
return MessageBox(hwnd, (LPSTR)text, (LPSTR)"WindowsApp", params[2] | params[3]);
}

Try to use:

static cell AMX_NATIVE_CALL n_MessageBox(AMX *amx, const cell *params)
{

cell* cptr; // PAWN string pointer.
char text[256]; // BUFFER to copy PAWN string in C.

// Get physical address (From PAWN to C)
if(amx_GetAddr(amx, params[1], &cptr) != AMX_ERR_NONE)
{
// Error. Wrong address.
return -1;
}

// Convert PAWN string to C string.
if(cptr)
{
amx_GetString(text, cptr, 0, 256);
}
else
{
//error. Invalid string address.
return -2;
}

return MessageBox(hwnd, (LPSTR)text, (LPSTR)"WindowsApp", params[2] | params[3]);

}

Well try that, maybe work.

I'm using PAWN for embedding devices (not computers)...

Regards

Boris Estudiez

--
Slicetex Electronics
www.slicetex.com.ar



[GF]Sasino97
Posted On 2011-09-05 13:26 -- Subject: RE: Some little errors, please help me :)

Thanks, I'll try
[GF]Sasino97
Posted On 2011-09-05 13:43 -- Subject: RE: Some little errors, please help me :)

Edit: It doesn't know what's amx_GetAddr

You Are On Page: 1/1 <<   <   1   >   >>




- BiTBOARD version 2.5 by the BiTSHiFTERS SDC -