Ejemplo n.º 1
0
void NdbMem_Create()
{
    // Address Windowing Extensions
    struct PRIVINFO
    {
        DWORD Count;
        LUID_AND_ATTRIBUTES Privilege[1];
    } Info;

    HANDLE hProcess = GetCurrentProcess();
    HANDLE hToken;
    if(!OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken))
    {
        ShowLastError("NdbMem_Create", "OpenProcessToken");
    }
    
    Info.Count = 1;
    Info.Privilege[0].Attributes = SE_PRIVILEGE_ENABLED;
    if(!LookupPrivilegeValue(0, SE_LOCK_MEMORY_NAME, &(Info.Privilege[0].Luid)))
    {
        ShowLastError("NdbMem_Create", "LookupPrivilegeValue");
    }
    
    if(!AdjustTokenPrivileges(hToken, FALSE, (PTOKEN_PRIVILEGES)&Info, 0, 0, 0))
    {
        ShowLastError("NdbMem_Create", "AdjustTokenPrivileges");
    }
    
    if(!CloseHandle(hToken))
    {
        ShowLastError("NdbMem_Create", "CloseHandle");
    }
    
    return;
}
Ejemplo n.º 2
0
static VOID DoSaveFile(VOID)
{
    HANDLE hFile;
    DWORD dwNumWrite;
    LPSTR pTemp;
    DWORD size;

    hFile = CreateFile(Globals.szFileName, GENERIC_WRITE, FILE_SHARE_WRITE,
                       NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    if(hFile == INVALID_HANDLE_VALUE)
    {
        ShowLastError();
        return;
    }

    size = GetWindowTextLengthA(Globals.hEdit) + 1;
    pTemp = HeapAlloc(GetProcessHeap(), 0, size);
    if (!pTemp)
    {
	CloseHandle(hFile);
        ShowLastError();
        return;
    }
    size = GetWindowTextA(Globals.hEdit, pTemp, size);

    if (!WriteFile(hFile, pTemp, size, &dwNumWrite, NULL))
        ShowLastError();
    else
        SendMessage(Globals.hEdit, EM_SETMODIFY, FALSE, 0);

    SetEndOfFile(hFile);
    CloseHandle(hFile);
    HeapFree(GetProcessHeap(), 0, pTemp);
}
Ejemplo n.º 3
0
VOID DoOpenFile(LPCTSTR szFileName)
{
    static const TCHAR dotlog[] = _T(".LOG");
    HANDLE hFile;
    LPTSTR pszText = NULL;
    DWORD dwTextLen;
    TCHAR log[5];

    /* Close any files and prompt to save changes */
    if (!DoCloseFile())
        return;

    hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
                       OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    if (hFile == INVALID_HANDLE_VALUE)
    {
        ShowLastError();
        goto done;
    }

    if (!ReadText(hFile, (LPWSTR *)&pszText, &dwTextLen, &Globals.iEncoding, &Globals.iEoln))
    {
        ShowLastError();
        goto done;
    }
#ifndef UNICODE
    pszText = ConvertToASCII(pszText);
    if (pszText == NULL) {
        ShowLastError();
        goto done;
    }
#endif
    SetWindowText(Globals.hEdit, pszText);

    SendMessage(Globals.hEdit, EM_SETMODIFY, FALSE, 0);
    SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
    SetFocus(Globals.hEdit);

    /*  If the file starts with .LOG, add a time/date at the end and set cursor after
     *  See http://support.microsoft.com/?kbid=260563
     */
    if (GetWindowText(Globals.hEdit, log, SIZEOF(log)) && !_tcscmp(log, dotlog))
    {
        static const TCHAR lf[] = _T("\r\n");
        SendMessage(Globals.hEdit, EM_SETSEL, GetWindowTextLength(Globals.hEdit), -1);
        SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)lf);
        DIALOG_EditTimeDate();
        SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)lf);
    }

    SetFileName(szFileName);
    UpdateWindowCaption();
    NOTEPAD_EnableSearchMenu();
done:
    if (hFile != INVALID_HANDLE_VALUE)
        CloseHandle(hFile);
    if (pszText)
        HeapFree(GetProcessHeap(), 0, pszText);
}
Ejemplo n.º 4
0
void* NdbMem_Allocate(size_t size)
{
    // Address Windowing Extensions
    struct AWEINFO* pAWEinfo;
    HANDLE hProcess;
    SYSTEM_INFO sysinfo;

    if(!gNdbMem_pAWEinfo)
    {
        gNdbMem_pAWEinfo = VirtualAlloc(0, 
            sizeof(struct AWEINFO)*cNdbMem_nMaxAWEinfo, 
            MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE);
    }

    assert(gNdbMem_nAWEinfo < cNdbMem_nMaxAWEinfo);
    pAWEinfo = gNdbMem_pAWEinfo+gNdbMem_nAWEinfo++;

    hProcess = GetCurrentProcess();
    GetSystemInfo(&sysinfo);
    pAWEinfo->nNumberOfPagesRequested = (size+sysinfo.dwPageSize-1)/sysinfo.dwPageSize;
    pAWEinfo->pnPhysicalMemoryPageArray = VirtualAlloc(0, 
        sizeof(ULONG_PTR)*pAWEinfo->nNumberOfPagesRequested, 
        MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE);
    pAWEinfo->nNumberOfPagesActual = pAWEinfo->nNumberOfPagesRequested;
    if(!AllocateUserPhysicalPages(hProcess, &(pAWEinfo->nNumberOfPagesActual), pAWEinfo->pnPhysicalMemoryPageArray))
    {
        ShowLastError("NdbMem_Allocate", "AllocateUserPhysicalPages");
        return 0;
    }
    if(pAWEinfo->nNumberOfPagesRequested != pAWEinfo->nNumberOfPagesActual)
    {
        ShowLastError("NdbMem_Allocate", "nNumberOfPagesRequested != nNumberOfPagesActual");
        return 0;
    }
    
    pAWEinfo->dwSizeInBytesRequested = size;
    pAWEinfo->pRegionReserved = VirtualAlloc(0, pAWEinfo->dwSizeInBytesRequested, MEM_RESERVE | MEM_PHYSICAL, PAGE_READWRITE);
    if(!pAWEinfo->pRegionReserved)
    {
        ShowLastError("NdbMem_Allocate", "VirtualAlloc");
        return 0;
    }
    
    if(!MapUserPhysicalPages(pAWEinfo->pRegionReserved, pAWEinfo->nNumberOfPagesActual, pAWEinfo->pnPhysicalMemoryPageArray))
    {
        ShowLastError("NdbMem_Allocate", "MapUserPhysicalPages");
        return 0;
    }

    /*
    printf("allocate AWE memory: %lu bytes, %lu pages, address %lx\n", 
        pAWEinfo->dwSizeInBytesRequested, 
        pAWEinfo->nNumberOfPagesActual,
        pAWEinfo->pRegionReserved);
    */
    return pAWEinfo->pRegionReserved;
}
Ejemplo n.º 5
0
BOOL InfFile::UninstallFiles(const char *pFilesSection) const
{
  if (!pPath)
    return FALSE;

  int res;
  HINF hInf;

  do {
    res = IDCONTINUE;

    UINT errLine;
    hInf = SetupOpenInfFile(pPath, NULL, INF_STYLE_WIN4, &errLine);

    if (hInf == INVALID_HANDLE_VALUE)
      res = ShowLastError(MB_CANCELTRYCONTINUE, "SetupOpenInfFile(%s) on line %u", pPath, errLine);
  } while (res == IDTRYAGAIN);

  if (res != IDCONTINUE)
    return FALSE;

  do {
    res = IDCONTINUE;

    HSPFILEQ hFileQueue = SetupOpenFileQueue();

    if (hFileQueue != INVALID_HANDLE_VALUE) {
      if (SetupQueueDeleteSection(hFileQueue, hInf, NULL, pFilesSection)) {
        PVOID pContext = SetupInitDefaultQueueCallback(NULL);

        if (pContext) {
          if(!SetupCommitFileQueue(NULL, hFileQueue, FileCallback, pContext))
            res = ShowLastError(MB_CANCELTRYCONTINUE, "SetupCommitFileQueue()");

          SetupTermDefaultQueueCallback(pContext);
        } else {
          res = ShowLastError(MB_CANCELTRYCONTINUE, "SetupInitDefaultQueueCallback()");
        }
      } else {
        res = ShowLastError(MB_CANCELTRYCONTINUE, "SetupQueueDeleteSection(%s)", pFilesSection);
      }

      SetupCloseFileQueue(hFileQueue);
    } else {
      res = ShowLastError(MB_CANCELTRYCONTINUE, "SetupOpenFileQueue()");
    }
  } while (res == IDTRYAGAIN);

  SetupCloseInfFile(hInf);

  if (res != IDCONTINUE)
    return FALSE;

  return TRUE;
}
Ejemplo n.º 6
0
static BOOL DoSaveFile(VOID)
{
    BOOL bRet = TRUE;
    HANDLE hFile;
    LPTSTR pTemp;
    DWORD size;

    hFile = CreateFile(Globals.szFileName, GENERIC_WRITE, FILE_SHARE_WRITE,
                       NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    if(hFile == INVALID_HANDLE_VALUE)
    {
        ShowLastError();
        return FALSE;
    }

    size = GetWindowTextLength(Globals.hEdit) + 1;
    pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(*pTemp));
    if (!pTemp)
    {
        CloseHandle(hFile);
        ShowLastError();
        return FALSE;
    }
    size = GetWindowText(Globals.hEdit, pTemp, size);

#ifndef UNICODE
    pTemp = (LPTSTR)ConvertToUNICODE(pTemp, &size);
    if (!pTemp)
    {
        /* original "pTemp" already freed */
        CloseHandle(hFile);
        ShowLastError();
        return FALSE;
    }
#endif

    if (size)
    {
        if (!WriteText(hFile, (LPWSTR)pTemp, size, Globals.iEncoding, Globals.iEoln))
        {
            ShowLastError();
            bRet = FALSE;
        }
        else
        {
            SendMessage(Globals.hEdit, EM_SETMODIFY, FALSE, 0);
            bRet = TRUE;
        }
    }

    CloseHandle(hFile);
    HeapFree(GetProcessHeap(), 0, pTemp);
    return bRet;
}
Ejemplo n.º 7
0
void Init() {
    if (!CreateTimerQueueTimer( &hTimer, NULL, TimerRoutine, hWnd, 1000, 1000, WT_EXECUTEDEFAULT)) {
        ShowLastError("CreateTimerQueueTimer");
        return;
    }

}
Ejemplo n.º 8
0
BOOL InfFile::UninstallOEMInf() const
{
  if (!pPath)
    return FALSE;

  int res;

  do {
    res = IDCONTINUE;

    char infPathDest[MAX_PATH];

    if (SetupCopyOEMInf(pPath, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, infPathDest,
        sizeof(infPathDest)/sizeof(infPathDest[0]), NULL, NULL))
    {
      UninstallInf(infPathDest);
    } else {
      if (GetLastError() == ERROR_FILE_NOT_FOUND) {
        Trace("File %s not installed\n", pPath);
      } else {
        res = ShowLastError(MB_CANCELTRYCONTINUE, "SetupCopyOEMInf(%s)", pPath);
      }
    }
  } while (res == IDTRYAGAIN);

  if (res != IDCONTINUE)
    return FALSE;

  return TRUE;
}
Ejemplo n.º 9
0
VOID DIALOG_EditWrap(VOID)
{
    BOOL modify = FALSE;
    static const WCHAR editW[] = { 'e','d','i','t',0 };
    DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL |
                    ES_AUTOVSCROLL | ES_MULTILINE;
    RECT rc;
    DWORD size;
    LPWSTR pTemp;

    size = GetWindowTextLengthW(Globals.hEdit) + 1;
    pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
    if (!pTemp)
    {
        ShowLastError();
        return;
    }
    GetWindowTextW(Globals.hEdit, pTemp, size);
    modify = SendMessageW(Globals.hEdit, EM_GETMODIFY, 0, 0);
    DestroyWindow(Globals.hEdit);
    GetClientRect(Globals.hMainWnd, &rc);
    if( Globals.bWrapLongLines ) dwStyle |= WS_HSCROLL | ES_AUTOHSCROLL;
    Globals.hEdit = CreateWindowExW(WS_EX_CLIENTEDGE, editW, NULL, dwStyle,
                         0, 0, rc.right, rc.bottom, Globals.hMainWnd,
                         NULL, Globals.hInstance, NULL);
    SendMessageW(Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, FALSE);
    SetWindowTextW(Globals.hEdit, pTemp);
    SendMessageW(Globals.hEdit, EM_SETMODIFY, modify, 0);
    SetFocus(Globals.hEdit);
    HeapFree(GetProcessHeap(), 0, pTemp);
    
    Globals.bWrapLongLines = !Globals.bWrapLongLines;
    CheckMenuItem(GetMenu(Globals.hMainWnd), CMD_WRAP,
        MF_BYCOMMAND | (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
}
Ejemplo n.º 10
0
//---------------------------------------------------------------------------
int __fastcall DebuggeeCheckThread::HandleDebugString( DEBUG_EVENT& debug )
{
    void* buffer;
    size_t len = debug.u.DebugString.nDebugStringLength;
    if( len == 0 ) return 1;
    bool isunicode = debug.u.DebugString.fUnicode ? true : false;

    if( isunicode ) {
        buffer = (void*)new wchar_t[len];
        len = len * sizeof(wchar_t);
    } else {
        buffer = (void*)new char[len];
        len = len * sizeof(char);
    }

    // デバッグ文字列を読み出す
    DWORD dwRead;
    BOOL result = ::ReadProcessMemory( proc_info_.hProcess, debug.u.DebugString.lpDebugStringData,
                                       buffer, len, &dwRead );
    if( result == 0 ) {
        ShowLastError();
    } else {
        if( isunicode ) {
            debug_string_ = AnsiString( (wchar_t*)buffer );
        } else {
            debug_string_ = AnsiString( (char*)buffer );
        }
        Synchronize(&SetDebugString);
    }
    delete[] buffer;
    return 1;
}
Ejemplo n.º 11
0
// ウィンドウを生成する
inline HWND WINAPI tapetums::UWnd::Create
(
    LPCTSTR lpszWindowName,
    DWORD   style,
    DWORD   styleEx,
    HWND    hwndParent,
    HMENU   hMenu
)
{
    if ( m_hwnd ) { return m_hwnd; } // 二重生成防止!

    const auto hwnd = ::CreateWindowEx
    (
        styleEx, m_class_name, lpszWindowName, style,
        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
        hwndParent, hMenu, ::GetModuleHandle(nullptr),
        reinterpret_cast<LPVOID>(this)
    );
    if ( nullptr == hwnd )
    {
        ShowLastError(class_name);
    }
    else
    {
        ::UpdateWindow(hwnd);
    }

    return hwnd;
}
Ejemplo n.º 12
0
void wmain(int argc, WCHAR *argv[])
{
    DWORD     dwSize;
    HANDLE    hToken;
    LPVOID    lpvEnv;
    PROCESS_INFORMATION pi = {0};
    STARTUPINFO         si = {0};
    WCHAR               szUserProfile[256] = L"";

    si.cb = sizeof(STARTUPINFO);

    if (argc != 4)
    {
        /*    wprintf(L"Usage: %s [user@domain] [password] [cmd]", argv[0]);
            wprintf(L"\n\n"); */
        //   return;
    }

    dwSize = sizeof(szUserProfile)/sizeof(WCHAR);


    OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&hToken);
    //ShowLastError(L"OpenProcessToken");
    //SetPrivilege(&hToken, SE_SYSTEMTIME_NAME,TRUE);
    // if(!SetPrivilege(hToken, SE_TCB_NAME , TRUE)) printf("Set Privilege Failed");// DisplayError(L"SetPrivilege");
    //if (!LogonUser(argv[1], NULL , argv[2], LOGON32_LOGON_INTERACTIVE,    LOGON32_PROVIDER_DEFAULT, &hToken))       DisplayError(L"LogonUser");

    if (!CreateEnvironmentBlock(&lpvEnv, hToken, TRUE))    ShowLastError(L"CreateEnvironmentBlock");

    dwSize = sizeof(szUserProfile)/sizeof(WCHAR);

    if (!GetUserProfileDirectory(hToken, szUserProfile, &dwSize))        ShowLastError(L"GetUserProfileDirectory");
    //
    // TO DO: change NULL to '.' to use local account database
    //
    if (!CreateProcessWithLogonW(argv[1], NULL, argv[2],             LOGON_WITH_PROFILE, NULL, argv[3],             CREATE_UNICODE_ENVIRONMENT, lpvEnv, szUserProfile,             &si, &pi))

        ShowLastError(L"CreateProcessWithLogonW");

    if (!DestroyEnvironmentBlock(lpvEnv))        ShowLastError(L"DestroyEnvironmentBlock");


    CloseHandle(hToken);
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);
}
Ejemplo n.º 13
0
/**
 * transmit a buffer
 * @param buff - char pointer to buffer
 * @param n - number of bytes in buffer to send
 * @returns zero on failure
 */
int tx(uint8_t* buff, int n)
{
    DWORD dwBytes = 0;
    if(!WriteFile(hSerial, buff, n, &dwBytes, NULL)){
        printf("Error writing port\n");
        ShowLastError();
        return 0;
    }
    return dwBytes;
}
Ejemplo n.º 14
0
static BOOL GetVersionInfo(const char *pInfPath, const char *pKey, char **ppValue, BOOL showErrors)
{
  if (!pInfPath)
    return FALSE;

  if (*ppValue)
    return TRUE;

  char buf[4000];

  if (!SetupGetInfInformation(pInfPath, INFINFO_INF_NAME_IS_ABSOLUTE, (PSP_INF_INFORMATION)buf, sizeof(buf), NULL)) {
    if (showErrors)
      ShowLastError(MB_OK|MB_ICONSTOP, "SetupGetInfInformation(%s)", pInfPath);
    return FALSE;
  }

  DWORD size;

  if (!SetupQueryInfVersionInformation((PSP_INF_INFORMATION)buf, 0, pKey, NULL, 0, &size)) {
    if (showErrors)
      ShowLastError(MB_OK|MB_ICONSTOP, "SetupQueryInfVersionInformation(%s) for %s", pKey, pInfPath);
    return FALSE;
  }

  *ppValue = (char *)LocalAlloc(LPTR, size*sizeof(*ppValue[0]));

  if (*ppValue) {
    if (!SetupQueryInfVersionInformation((PSP_INF_INFORMATION)buf, 0, pKey, *ppValue, size, NULL)) {
      if (showErrors)
        ShowLastError(MB_OK|MB_ICONSTOP, "SetupQueryInfVersionInformation(%s) for %s", pKey, pInfPath);
      LocalFree(*ppValue);
      *ppValue = NULL;
      return FALSE;
    }
  } else {
    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
    ShowLastError(MB_OK|MB_ICONSTOP, "LocalAlloc(%lu)", (unsigned long)(size*sizeof(*ppValue[0])));
    return FALSE;
  }

  return TRUE;
}
Ejemplo n.º 15
0
/**
 * receive a buffer
 * @param buff - char pointer to buffer
 * @param n - number of bytes in buffer to read
 * @returns number of bytes read
 */
int rx(uint8_t* buff, int n)
{
    DWORD dwBytes = 0;
    SetCommTimeouts(hSerial, &original_timeouts);
    if(!ReadFile(hSerial, buff, n, &dwBytes, NULL)){
        printf("Error reading port\n");
        ShowLastError();
        return 0;
    }
    return dwBytes;
}
Ejemplo n.º 16
0
VOID 
ShowNTError( 
	LPSTR szAPI, 
	NTSTATUS Status 
	) 
{     
    // 
    // Convert the NTSTATUS to Winerror. Then call ShowLastError().     
    // 
    ShowLastError(szAPI, LsaNtStatusToWinError(Status));
} 
Ejemplo n.º 17
0
BOOL StopService(CServiceManager* sm)
{
  PanelInfo pi;
  ZeroMemory(&pi, sizeof(PanelInfo));
  pi.StructSize = sizeof(PanelInfo);
  if (Info.PanelControl(PANEL_ACTIVE, FCTL_GETPANELINFO, 0, &pi))
  {
    size_t CurItem = pi.CurrentItem;
    if (CurItem > 0)
    {
      size_t Size = Info.PanelControl(PANEL_ACTIVE,FCTL_GETPANELITEM, CurItem, 0);
      PluginPanelItem *PPI=(PluginPanelItem*)malloc(Size);
      if (PPI)
      {
        FarGetPluginPanelItem FGPPI = {Size, PPI};
        Info.PanelControl(PANEL_ACTIVE, FCTL_GETPANELITEM, CurItem, &FGPPI);

        size_t Index = FGPPI.Item->UserData;
        free(PPI);

        if (Index < sm->GetCount())
        {
          bool bStop = sm->StopService(Index);
          if (bStop)
          {
            ShowMessage(NULL, L"Stopping service...", FMSG_NONE);

            int nWait = 300;
            while (true)
            {
              SERVICE_STATUS_PROCESS QueryServiceStatus;
              if (sm->QueryServiceStatus(Index, QueryServiceStatus)
                && QueryServiceStatus.dwCurrentState == SERVICE_STOPPED)
              {
                break;
              }
              Sleep(100);
              nWait -= 1;
              if (!nWait)
                break;
            }
            UpdatePanel(true);
            RedrawPanel(true);
            RedrawPanel(false);
          }
          else
            ShowLastError(&MsgCantStopServiceGuid);
        }
      }
    }
  }

  return TRUE;
}
Ejemplo n.º 18
0
/**
 * receive a buffer with a timeout
 * @param buff - char pointer to buffer
 * @param n - number of bytes in buffer to read
 * @param timeout - timeout in milliseconds
 * @returns number of bytes read or SERIAL_TIMEOUT
 */
int rx_timeout(uint8_t* buff, int n, int timeout)
{
    DWORD dwBytes = 0;
    timeouts.ReadTotalTimeoutConstant = timeout;
    SetCommTimeouts(hSerial, &timeouts);
    if(!ReadFile(hSerial, buff, n, &dwBytes, NULL)){
        printf("Error reading port\n");
        ShowLastError();
        return 0;
    }
    return dwBytes > 0 ? dwBytes : SERIAL_TIMEOUT;
}
Ejemplo n.º 19
0
void NdbMem_Free(void* ptr)
{
    // VirtualFree(ptr, 0, MEM_DECOMMIT|MEM_RELEASE);
    
    // Address Windowing Extensions
    struct AWEINFO* pAWEinfo = 0;
    size_t i;
    HANDLE hProcess;

    for(i=0; i<gNdbMem_nAWEinfo; ++i)
    {
        if(ptr==gNdbMem_pAWEinfo[i].pRegionReserved)
        {
            pAWEinfo = gNdbMem_pAWEinfo+i;
        }
    }
    if(!pAWEinfo)
    {
        ShowLastError("NdbMem_Free", "ptr is not AWE memory");
    }

    hProcess = GetCurrentProcess();
    if(!MapUserPhysicalPages(ptr, pAWEinfo->nNumberOfPagesActual, 0))
    {
        ShowLastError("NdbMem_Free", "MapUserPhysicalPages");
    }
    
    if(!VirtualFree(ptr, 0, MEM_RELEASE))
    {
        ShowLastError("NdbMem_Free", "VirtualFree");
    }
    
    pAWEinfo->nNumberOfPagesFreed = pAWEinfo->nNumberOfPagesActual;
    if(!FreeUserPhysicalPages(hProcess, &(pAWEinfo->nNumberOfPagesFreed), pAWEinfo->pnPhysicalMemoryPageArray))
    {
        ShowLastError("NdbMem_Free", "FreeUserPhysicalPages");
    }
    
    VirtualFree(pAWEinfo->pnPhysicalMemoryPageArray, 0, MEM_DECOMMIT|MEM_RELEASE);
}
Ejemplo n.º 20
0
HANDLE WINAPI OpenW(const struct OpenInfo *oi)
{
  CServiceManager* sm = new CServiceManager(g_Settings.sComputer);

  wstring sMsg = L"Connecting to " + (g_Settings.sComputer.length() > 0 ? g_Settings.sComputer : GetComputerName());
  ShowMessage(NULL, sMsg.c_str(), FMSG_NONE);
  bool bInit = sm->Init();
  
  if (!bInit)
    ShowLastError(&CantConnectToMachineMsgGuid);

  return (HANDLE)sm;
}
Ejemplo n.º 21
0
LPBYTE OpenFileRam(LPTSTR fileName, LPDWORD size)
{
	if (fileName[0] == NULL)
		return false;
	LPBYTE data;
	HANDLE hFile = CreateFile(fileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
	if (hFile != INVALID_HANDLE_VALUE)
	{
		*size = GetFileSize(hFile, NULL);
		if (*size == INVALID_FILE_SIZE)
		{
			MessageBox(NULL, "GetFileSize", "Error", MB_ICONERROR);
			ShowLastError(GetLastError());
			CloseHandle(hFile);
			return false;
		}
		data = (LPBYTE)Malloc(*size);

		DWORD bytesR;
		if (!ReadFile(hFile, data, *size, &bytesR, NULL))
		{
			MessageBox(NULL, "ReadFile", "Error", MB_ICONERROR);
			ShowLastError(GetLastError());
			Free(data);
			return false;
		}
		if (*size != bytesR)
		{
			MessageBox(NULL, "Bytes Read", "Error", MB_ICONERROR);
			ShowLastError(GetLastError());
			Free(data);
			return false;
		}
		CloseHandle(hFile);
		return data;
	}
	ShowLastError(GetLastError());
	return NULL;
}
Ejemplo n.º 22
0
static BOOL UninstallInf(const char *pPath)
{
  int res;

  do {
    res = IDCONTINUE;

    char infPathDest[MAX_PATH];

    if (SNPRINTF(infPathDest, sizeof(infPathDest)/sizeof(infPathDest[0]), "%s", pPath) > 0) {
#ifdef HAVE_SetupUninstallOEMInf
      char *pInfNameDest, *p;

      for (pInfNameDest = p = infPathDest ; *p ; p++)
        if (*p == '\\')
          pInfNameDest = p + 1;

      if (SetupUninstallOEMInf(pInfNameDest, 0, NULL)) {
        Trace("Deleted %s\n", pInfNameDest);
      } else {
        res = ShowLastError(MB_CANCELTRYCONTINUE, "SetupUninstallOEMInf(%s)", pInfNameDest);
      }
#else /* HAVE_SetupUninstallOEMInf */
      if (UninstallFile(infPathDest)) {
        int infPathDestLen = lstrlen(infPathDest);

        if (infPathDestLen > 4) {
          char *pInfPathDestExt = infPathDest + infPathDestLen - 4;

          if (!lstrcmpi(pInfPathDestExt, ".inf")) {
            pInfPathDestExt[1] = 'p';     // pInfPathDestExt = ".pnf"

            if (!UninstallFile(infPathDest))
              res = IDCANCEL;
          }
        }
      } else {
        res = IDCANCEL;
      }
#endif /* HAVE_SetupUninstallOEMInf */
    } else {
      Trace("Can't uninstall %s\n", pPath);
      res = IDCANCEL;
    }
  } while (res == IDTRYAGAIN);

  if (res != IDCONTINUE)
    return FALSE;

  return res;
}
Ejemplo n.º 23
0
/*
 * Exit the program and give a nice and firm explanation of why
 * and how you can avoid it.
 */
void exit_help(char *err)
{
    ShowLastError();
    fprintf(stderr, "** Error: %s\n", err);

    printf("Usage:\n%s\n"
           "      [<erlang options>] ++\n"
           "      [-data <datafile>]\n"
           "      [-reldir <releasedir>]\n"
           "      [-bootflags <bootflagsfile>]\n"
           "      [-noconfig]\n", progname);

    exit(0);
}
Ejemplo n.º 24
0
static bool ChangeState(HDEVINFO hDevInfo, PSP_DEVINFO_DATA pDevInfoData, DWORD stateChange)
{
  SP_PROPCHANGE_PARAMS propChangeParams;

  memset(&propChangeParams, 0, sizeof(propChangeParams));
  propChangeParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
  propChangeParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
  propChangeParams.StateChange = stateChange;
  propChangeParams.Scope = DICS_FLAG_CONFIGSPECIFIC;
  propChangeParams.HwProfile = 0;

  if (!SetupDiSetClassInstallParams(hDevInfo, pDevInfoData, (SP_CLASSINSTALL_HEADER *)&propChangeParams, sizeof(propChangeParams))) {
    ShowLastError(MB_OK|MB_ICONSTOP, "SetupDiSetClassInstallParams()");
    return FALSE;
  }

  if (!SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, hDevInfo, pDevInfoData)) {
    ShowLastError(MB_OK|MB_ICONSTOP, "SetupDiCallClassInstaller(DIF_PROPERTYCHANGE)");
    return FALSE;
  }

  return TRUE;
}
Ejemplo n.º 25
0
static BOOL GetFilePath(
    const char *pFileName,
    const char *pNearPath,
    char *pFilePath,
    DWORD lenFilePath)
{
  char *pBuf;
  DWORD res;

  if (!pNearPath) {
    if (DWORD(lstrlen(pFileName)) >= lenFilePath) {
      ShowError(MB_OK|MB_ICONSTOP, ERROR_BUFFER_OVERFLOW, "lstrlen(%s) >= %lu",
                pFileName, (long)lenFilePath);
      return FALSE;
    }

    lstrcpy(pFilePath, pFileName);

    return TRUE;
  }

  res = GetFullPathName(pNearPath, lenFilePath, pFilePath, &pBuf);

  if (!res) {
    ShowLastError(MB_OK|MB_ICONSTOP, "GetFullPathName(%s)", pNearPath);
    return FALSE;
  }

  if (res >= lenFilePath) {
    ShowError(MB_OK|MB_ICONSTOP, ERROR_BUFFER_OVERFLOW, "GetFullPathName(%s)", pNearPath);
    return FALSE;
  }

  if (!pBuf) {
    ShowError(MB_OK|MB_ICONSTOP, ERROR_INVALID_NAME, "GetFullPathName(%s)", pNearPath);
    return FALSE;
  }

  if (DWORD(pBuf - pFilePath + lstrlen(pFileName)) >= lenFilePath) {
    ShowError(MB_OK|MB_ICONSTOP, ERROR_BUFFER_OVERFLOW, "GetFullPathName(%s)", pNearPath);
    return FALSE;
  }

  lstrcpy(pBuf, pFileName);

  //ShowMsg(MB_OK, "pFilePath=%s\n", pFilePath);

  return TRUE;
}
Ejemplo n.º 26
0
bool RemoveDevice(
    HDEVINFO hDevInfo,
    PSP_DEVINFO_DATA pDevInfoData,
    PCDevProperties pDevProperties,
    BOOL *pRebootRequired)
{
  if (!SetupDiCallClassInstaller(DIF_REMOVE, hDevInfo, pDevInfoData)) {
    ShowLastError(MB_OK|MB_ICONSTOP, "SetupDiCallClassInstaller(DIF_REMOVE, %s, %s)",
                  pDevProperties->DevId(), pDevProperties->PhObjName());
    return FALSE;
  }

  Trace("Removed %s %s %s\n", pDevProperties->Location(), pDevProperties->DevId(), pDevProperties->PhObjName());

  return UpdateRebootRequired(hDevInfo, pDevInfoData, pRebootRequired);
}
Ejemplo n.º 27
0
//-----------------------------------------------------------------------------
// Name: ShowDialog()
// Desc: Displays the dialog
//
// hinst: Application instance
// hwnd:  Handle to the parent window. Use NULL if no parent.
//
// Returns TRUE if successful or FALSE otherwise
//-----------------------------------------------------------------------------
BOOL CBaseDialog::ShowDialog(HINSTANCE hinst, HWND hwnd)
{
    // Cache these...
    m_hinst = hinst;
    m_hwnd = hwnd;

    // Show the dialog. Pass a pointer to ourselves as the LPARAM
    INT_PTR ret = DialogBoxParam(hinst, MAKEINTRESOURCE(m_nID), 
        hwnd, DialogProc, (LPARAM)this);

    if (ret == 0 || ret == -1)
    {
        ShowLastError(NULL);
        return FALSE;
    }

    return (IDOK == ret);
}
Ejemplo n.º 28
0
HRESULT __stdcall UWnd::Create
(
    LPCTSTR lpWindowName,
    DWORD   style, 
    DWORD   styleEx,
    HWND    hwndParent,
    HMENU   hMenu
)
{
    console_out(TEXT("UWnd::Create(\"%s\") begin"), m_classname);

    // 二重生成防止!
    if ( m_hwnd )
    {
        console_out(TEXT("Already created"));
        console_out(TEXT("UWnd::Create(%s) end"), m_classname);
        return S_FALSE;
    }

    // 親ウィンドウを持つ場合はウィンドウスタイルにWS_CHILDを追加
    style |= hwndParent ? WS_CHILD : 0;

    // ウィンドウを生成 … UWnd::StaticWndProc() 内で m_hwnd を格納している
    ::CreateWindowEx
    (
        styleEx, m_classname, lpWindowName, style,
        m_x, m_y, m_w, m_h,
        hwndParent, hMenu, ::GetModuleHandle(nullptr), (LPVOID)this
    );
    if ( nullptr == m_hwnd )
    {
        // エラーメッセージの表示
        ShowLastError(m_classname);
    }
    else
    {
        ::UpdateWindow(m_hwnd);
    }

    console_out(TEXT("UWnd::Create(\"%s\") end"), m_classname);

    return m_hwnd ? S_OK : E_FAIL;
}
Ejemplo n.º 29
0
BOOL InfFile::InstallOEMInf() const
{
  if (!pPath)
    return FALSE;

  if (!SetupCopyOEMInf(pPath, NULL, SPOST_PATH, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL)) {
    char infPathDest[MAX_PATH];

    if (!SetupCopyOEMInf(pPath, NULL, SPOST_PATH, 0, infPathDest,
        sizeof(infPathDest)/sizeof(infPathDest[0]), NULL, NULL))
    {
      ShowLastError(MB_OK|MB_ICONSTOP, "SetupCopyOEMInf(%s)", pPath);
      return FALSE;
    }

    Trace("Installed %s to %s\n", pPath, infPathDest);
  }

  return TRUE;
}
Ejemplo n.º 30
0
InfFile::InfFile(const char *pInfName, const char *pNearPath)
  : pPath(NULL),
    pClassGUID(NULL),
    pClass(NULL),
    pProvider(NULL)
{
  char path[MAX_PATH];

  if (GetFilePath(pInfName, pNearPath, path, sizeof(path)/sizeof(path[0]))) {
    int len = lstrlen(path);

    pPath = (char *)LocalAlloc(LPTR, (len + 1)*sizeof(path[0]));

    if (pPath) {
      lstrcpy(pPath, path);
    } else {
      SetLastError(ERROR_NOT_ENOUGH_MEMORY);
      ShowLastError(MB_OK|MB_ICONSTOP, "LocalAlloc(%lu)", (unsigned long)(sizeof(path)/sizeof(path[0])));
    }
  }
}