Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8285115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:22:38+00:00 2026-06-08T11:22:38+00:00

I compiled the following code which is declared with #include <strsafe.h> in my C

  • 0

I compiled the following code which is declared with #include <strsafe.h> in my C code and I am getting the following compiler errors in DEV-C++. I guess there should be some option in compiler to solve this. Can somebody help to solve this.

The below is my sample code which is taken from MSDN site :

#include <windows.h>
#include <strsafe.h>

void ErrorExit(LPTSTR lpszFunction) 
{ 
    // Retrieve the system error message for the last-error code

    LPVOID lpMsgBuf;
    LPVOID lpDisplayBuf;
    DWORD dw = GetLastError(); 

    FormatMessage(
        FORMAT_MESSAGE_ALLOCATE_BUFFER | 
        FORMAT_MESSAGE_FROM_SYSTEM |
        FORMAT_MESSAGE_IGNORE_INSERTS,
        NULL,
        dw,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        (LPTSTR) &lpMsgBuf,
        0, NULL );

    // Display the error message and exit the process

    lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, 
        (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) * sizeof(TCHAR)); 
    StringCchPrintf((LPTSTR)lpDisplayBuf, 
        LocalSize(lpDisplayBuf) / sizeof(TCHAR),
        TEXT("%s failed with error %d: %s"), 
        lpszFunction, dw, lpMsgBuf); 
    MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK); 

    LocalFree(lpMsgBuf);
    LocalFree(lpDisplayBuf);
    ExitProcess(dw); 
}

void main()
{
    // Generate an error

    if(!GetProcessId(NULL))
        ErrorExit(TEXT("GetProcessId"));
}

A sample of errors from the huge set of errors.

154 26  C:\Documents and Settings\mkumar@hubino\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h   
[Error] expected '=', ',', ';', 'asm' or '__attribute__' before 'char'
155 26  C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h  
[Error] expected '=', ',', ';', 'asm' or '__attribute__' before 'const'
156 1   C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h  
[Error] unknown type name '__nullterminated'
156 33  C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h  
[Error] expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
157 26  C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h  
[Error] expected '=', ',', ';', 'asm' or '__attribute__' before 'const'
158 26  C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h  
[Error] expected '=', ',', ';', 'asm' or '__attribute__' before 'const'
164 38  C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h  
[Error] expected '=', ',', ';', 'asm' or '__attribute__' before 'const'
165 38  C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h  
[Error] expected '=', ',', ';', 'asm' or '__attribute__' before 'const'
166 38  C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h
[Error] expected '=', ',', ';', 'asm' or '__attribute__' before 'const'
173 10  C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h  
[Error] unknown type name 'STRSAFE_PCNZCH'
174 10  C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h  
[Error] unknown type name '__in_range'
175 15  C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h  
[Error] unknown type name '__deref_out_range'
179 10  C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h  
[Error] unknown type name 'STRSAFE_PCNZWCH'
180 10  C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h  
[Error] unknown type name '__in_range'
181 15  C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h  
[Error] unknown type name '__deref_out_range'
193 5   C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h  
[Error] unknown type name '__deref_in_opt_out'
194 17  C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h  
[Error] unknown type name '__deref_out_range'
200 5   C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h  
[Error] unknown type name '__deref_in_opt_out'
201 17  C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h  
[Error] unknown type name '__deref_out_range'
207 30  C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h  
[Error] unknown type name 'STRSAFE_PCNZCH'
213 30  C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h  
[Error] unknown type name 'STRSAFE_LPCSTR'
continues.......

A part of strsafe.h file from where I am getting the above errors :

//
// These typedefs are used in places where the string is guaranteed to
// be null terminated.
//
typedef __nullterminated char* STRSAFE_LPSTR;
typedef __nullterminated const char* STRSAFE_LPCSTR;
typedef __nullterminated wchar_t* STRSAFE_LPWSTR;
typedef __nullterminated const wchar_t* STRSAFE_LPCWSTR;
typedef __nullterminated const wchar_t UNALIGNED* STRSAFE_LPCUWSTR;

//
// These typedefs are used in places where the string is NOT guaranteed to
// be null terminated.
//
typedef __possibly_notnullterminated const char* STRSAFE_PCNZCH;
typedef __possibly_notnullterminated const wchar_t* STRSAFE_PCNZWCH;
typedef __possibly_notnullterminated const wchar_t UNALIGNED* STRSAFE_PCUNZWCH;


// prototypes for the worker functions

STRSAFEWORKERAPI
StringLengthWorkerA(
    __in STRSAFE_PCNZCH psz,
    __in __in_range(<=, STRSAFE_MAX_CCH) size_t cchMax,
    __out_opt __deref_out_range(<, cchMax) size_t* pcchLength);

STRSAFEWORKERAPI
StringLengthWorkerW(
    __in STRSAFE_PCNZWCH psz,
    __in __in_range(<=, STRSAFE_MAX_CCH) size_t cchMax,
    __out_opt __deref_out_range(<, cchMax) size_t* pcchLength);

#ifdef ALIGNMENT_MACHINE
STRSAFEWORKERAPI
UnalignedStringLengthWorkerW(
    __in STRSAFE_PCUNZWCH psz,
    __in __in_range(<=, STRSAFE_MAX_CCH) size_t cchMax,
    __out_opt __deref_out_range(<, cchMax) size_t* pcchLength);
#endif  // ALIGNMENT_MACHINE

STRSAFEWORKERAPI
StringExValidateSrcA(
    __deref_in_opt_out STRSAFE_LPCSTR* ppszSrc,
    __inout_opt __deref_out_range(<, cchMax) size_t* pcchToRead,
    __in const size_t cchMax,
    __in DWORD dwFlags);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:22:40+00:00Added an answer on June 8, 2026 at 11:22 am

    __nullterminated, __out_opt, __in, __in_opt and other such words are Microsoft-specific keywords. When you use gcc you can just define them to be empty macros like

    #define __in
    #define __deref_out_range(A,B)
    ... and so on
    

    Insert these defines before the includes.

    Or as the comments suggest avoid using the <strsafe.h>

    EDIT:

    MinGW (x64 build from http://equation.com) compiles this code above quietly (even with strsafe.h) with just a simple command:

    gcc -c Test.cpp -o Test.exe -lstdc++
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following line of code which when compiled with GHC it goes
Consider the following code which shows compile time error : #include <stdio.h> int main(int
I'm trying to compile some code which contains the following declaration, because I would
I have the following code compiled by gcc: #include <iostream> using namespace std; class
When I compile the following code, I only see the error during Run-time which
i have the following code snippet in my ANT File which compiles my project
I have the following code, which compiles but doesn't bring back any data. Here
I'm using the following code in CoffeeScript: if elem in my_array do_something() Which compiles
I compiled the following code as a shared library using g++ -shared ... :
The following code when compiled give this error I cannot understand why this is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.