EDN Admin
Well-known member
Compilers tested:
Visual Studio 2010 Professional
Pelles C
------------------------------------------
I have three files like so:<br/>
MyString.h
<pre class="prettyprint int __stdcall my_strlenA(char*);
int __stdcall my_strlenW(wchar_t*);
#ifdef UNICODE
#define my_strlen my_strlenW
#define my_strcpy my_strcpyW
#else
#define my_strlen my_strlenA
#define my_strcpy my_strcpyA
#endif[/code]
<br/>
MyString.c
<pre class="prettyprint #include "MyString.h"
/*
Get string length.
@Version: UNICODE
*/
__declspec(naked) int __stdcall my_strlenW(wchar_t * string){
__asm{
push ebp
mov ebp, esp
push esi
xor ecx, ecx
mov esi, string
iter:
lodsw
cmp ax, 0
je halt
lea ecx, [ecx+1]
jmp iter
halt:
pop esi
mov esp, ebp
pop ebp
mov eax, ecx
ret 4
}
}
/*
Get string length.
@Version: ANSI
*/
__declspec(naked) int __stdcall my_strlenA(char * string){
__asm{
push ebp
mov ebp, esp
push esi
xor ecx, ecx
mov esi, string
iter:
lodsb
cmp al, 0
je halt
lea ecx, [ecx+1]
jmp iter
halt:
pop esi
mov esp, ebp
pop ebp
mov eax, ecx
ret 4
}
}[/code]
<br/>
main.c
<pre class="prettyprint #include <Windows.h>
#include <tchar.h>
#include "MyString.h"
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
TCHAR buffer[] = {L"This is my ubber long string"};
TCHAR txt[100] = {0};
wsprintf(txt,L"string length: %d",my_strlen(buffer));
MessageBox(0,txt,0,MB_OK);
return (0);
}[/code]
<br/>
A ton of errors come up sourcing from MySytring.h
<span class="x_t-marker So the question is, since when is Visual Studio not aware of char * and
wchar_t * primitively that I have to include windows.h
for the said data types to be "defined" ?
The same errors are also generated by Pelles C.
<span class="x_t-marker
<span class="x_t-marker To solve this I have to include
windows.h in MyString.h
Why is this ? Since when ?<br/>
<hr class="sig chx101
View the full article
Visual Studio 2010 Professional
Pelles C
------------------------------------------
I have three files like so:<br/>
MyString.h
<pre class="prettyprint int __stdcall my_strlenA(char*);
int __stdcall my_strlenW(wchar_t*);
#ifdef UNICODE
#define my_strlen my_strlenW
#define my_strcpy my_strcpyW
#else
#define my_strlen my_strlenA
#define my_strcpy my_strcpyA
#endif[/code]
<br/>
MyString.c
<pre class="prettyprint #include "MyString.h"
/*
Get string length.
@Version: UNICODE
*/
__declspec(naked) int __stdcall my_strlenW(wchar_t * string){
__asm{
push ebp
mov ebp, esp
push esi
xor ecx, ecx
mov esi, string
iter:
lodsw
cmp ax, 0
je halt
lea ecx, [ecx+1]
jmp iter
halt:
pop esi
mov esp, ebp
pop ebp
mov eax, ecx
ret 4
}
}
/*
Get string length.
@Version: ANSI
*/
__declspec(naked) int __stdcall my_strlenA(char * string){
__asm{
push ebp
mov ebp, esp
push esi
xor ecx, ecx
mov esi, string
iter:
lodsb
cmp al, 0
je halt
lea ecx, [ecx+1]
jmp iter
halt:
pop esi
mov esp, ebp
pop ebp
mov eax, ecx
ret 4
}
}[/code]
<br/>
main.c
<pre class="prettyprint #include <Windows.h>
#include <tchar.h>
#include "MyString.h"
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
TCHAR buffer[] = {L"This is my ubber long string"};
TCHAR txt[100] = {0};
wsprintf(txt,L"string length: %d",my_strlen(buffer));
MessageBox(0,txt,0,MB_OK);
return (0);
}[/code]
<br/>
A ton of errors come up sourcing from MySytring.h
<span class="x_t-marker So the question is, since when is Visual Studio not aware of char * and
wchar_t * primitively that I have to include windows.h
for the said data types to be "defined" ?
The same errors are also generated by Pelles C.
<span class="x_t-marker
<span class="x_t-marker To solve this I have to include
windows.h in MyString.h
Why is this ? Since when ?<br/>
<hr class="sig chx101
View the full article