Visual studio does not recognize char* and wchar_t* when not including windows.h
-
Friday, September 14, 2012 5:15 AM
Compilers tested:
Visual Studio 2010 Professional
Pelles C
------------------------------------------
I have three files like so:
MyString.h
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
MyString.c
#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 } }
main.c
#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); }
A ton of errors come up sourcing from MySytring.h
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.
To solve this I have to include windows.h in MyString.h
Why is this ? Since when ?
chx101
- Moved by Ego JiangMicrosoft Contingent Staff Monday, September 17, 2012 3:12 AM it is a c++ issue (From:MSBuild)
All Replies
-
Monday, September 17, 2012 3:11 AM
Hi chx101,
Based on this case relate to Visual C++ General . I will move your case to Visual C++ General for better help.
Thank you for your understanding and support.
Best regards,
Ego [MSFT]
MSDN Community Support | Feedback to us
- Edited by Ego JiangMicrosoft Contingent Staff Monday, September 17, 2012 8:17 AM
-
Monday, September 17, 2012 3:44 AM

