|
|
When specifying the needed include files we have included the gxsdldr.cpp loader file directly:
#include "gxsd.h" #include "gxerror.h" #include "gxsdldr.cpp"
Specifying the used namespaces:
gx for to reach the API functions if the GX_NAMESPACES define is globally setstd for the display functions
/* Specifying the used namespaces */ #ifdef GX_NAMESPACES using namespace gx; #endif using namespace std;
Starting the main function:
int main(void) {
Setting new error code and message:
/* Unicode version */
{
/* Updates the system error buffer */
gxSystem::SetError(GX_EINVAL, L"(Test string [%i %hs %ls])", (int)1234, "ABC", L"ABC");
Displaying the error code and message:
/* Gets the error and displays it */
wcout << L"Error code: " << gxSystem::GetErrorCode() <<
L", Description: '" << gxSystem::GetErrorString() << L"'" << endl;
}
And the same in ASCII version:
/* ASCII version */
{
/* Updates the system error buffer */
gxSystem::SetError(GX_EINVAL, "(Test string [%i %hs %ls])", (int)1234, "ABC", L"ABC");
/* Gets the error and displays it */
cout << "Error code: " << gxSystem::GetErrorCode() <<
", Description: '" << gxSystem::GetErrorStringA() << "'" << endl;
}
And the sample program ends:
return 0;
}
When specifying the needed include files we have included the gxsdldr.cpp loader file directly:
#include "gxsd.h" #include "gxerror.h" #include "gxsdldr.cpp"
Specifying the used namespaces:
gx for to reach the API functions if the GX_NAMESPACES define is globally setstd for the display functions
/* Specifying the used namespaces */ #ifdef GX_NAMESPACES using namespace gx; #endif using namespace std;
Starting the main function:
int main(void) {
Clearing the error buffer:
/* Clears the error buffer */
gxSystem::ClearError();
Displaying the error code (0 - GX_ENOERR) and message (''):
/* Gets the error code and description text */
wcout << L"1. Error code: " << gxSystem::GetErrorCode() <<
L", Description: '" << gxSystem::GetErrorString() << L"'" << endl;
Setting and displaying the new error code and message:
/* Sets a new error code and description text */
gxSystem::SetError(GX_EINVAL, (const wchar_t *)L"%hs", "(Error occurred in my test application)");
/* Gets the second error code and description text */
wcout << L"2. Error code: " << gxSystem::GetErrorCode() <<
L", Description: '" << gxSystem::GetErrorString() << L"'" << endl;
And the sample program ends:
return 0;
}
When specifying the needed include files we have included the gxsdldr.cpp loader file directly:
#include <iomanip> #include "gxsd.h" #include "gxerror.h" #include "gxsdldr.cpp"
Specifying the used namespaces:
gx for to reach the API functions if the GX_NAMESPACES define is globally setstd for the display functions
/* Specifying the used namespaces */ #ifdef GX_NAMESPACES using namespace gx; #endif using namespace std;
Starting the main function:
int main(void) {
Setting new error code and message:
/* Sets some error code and description text (no format string) */ gxSystem::SetError(GX_EINVAL, L"%hs", "Line #1: Error occurred");
Appending new error message to the back of the error buffer and overriding the error code:
gxSystem::AppendError(GX_EREAD, L"%hs", "Line #2: Read error occurred");
Appending new error message to the front of the error buffer and overriding the error code:
gxSystem::PrependError(GX_EWRITE, L"%hs", "Line #0: Write error occurred");
Getting and displaying the error code and message:
/* Gets the error code and description text */
int err_code;
char err_str[256];
err_str[sizeof(err_str)-1] = 0;
gxSystem::GetError(&err_code, err_str, sizeof(err_str)-1);
/* Displays the error code and description text */
cout << "Error code: 0x" << hex << setw(8) << setfill('0') << err_code <<
"Description: '" << err_str << "'" << endl;
And the sample program ends:
return 0;
}
When specifying the needed include files we have included the gxsdldr.cpp loader file directly:
#include "gxsd.h" #include "gxerror.h" #include "gxsdldr.cpp"
Specifying the used namespaces:
gx for to reach the API functions if the GX_NAMESPACES define is globally setstd for the display functions
/* Specifying the used namespaces */ #ifdef GX_NAMESPACES using namespace gx; #endif
Including platform specific interface(s):
#include <windows.h>
Defining a thread function that has the error code as parameter:
DWORD WINAPI my_thread_func(LPVOID err_arg) {
gxSystem::SetError((int)err_arg);
for(int ix = 0; ix < 5; ix++) {
printf("Thread %08x: error code is %08x\n",
(int)GetCurrentThreadId(), gxSystem::GetErrorCode());
Sleep(2000);
}
ExitThread(0);
return 0;
}
Starting the main function:
int main(void) {
Defining the two threads:
HANDLE thread1, thread2;
Creating and starting the first thread:
/* Creates the first thread with arguments GX_ECREAT */
thread1 = CreateThread(0, 0, my_thread_func, (LPVOID)GX_ECREAT, 0, NULL);
if(thread1 == NULL) {
fprintf(stderr, "CreateThread() error: %i\n", GetLastError());
return 1;
}
Waiting for a short time:
Sleep(1000);
Creating and starting the second thread:
/* Creates the second thread with arguments GX_EREAD */
thread2 = CreateThread(0, 0, my_thread_func, (LPVOID)GX_EREAD, 0, NULL);
if(thread2 == 0) {
fprintf(stderr, "CreateThread() error: %i\n", GetLastError());
return 1;
}
Waiting for the threads to finish their job and ending the sample program:
/* Synchronizes */
WaitForSingleObject(thread1, INFINITE);
CloseHandle(thread1);
WaitForSingleObject(thread2, INFINITE);
CloseHandle(thread2);
return 0;
}