Example #1
0
File: win.c Project: IBwWG/systools
/* 
 * Based on: 
 * http://www.koders.com/c/fidFB995E4CBABD7E2D87CD5C771C59EBF4EBB5B803.aspx 
 * Copyright: (c) 2000, 2001, 2002, 2003 Thomas Heller 
 */
int systools_win_replaceExeIcon( const char *exe, const char *ico, int iconResourceID ) {	
	/* from the .ico file */
    ICONDIRHEADER *pidh;
    WORD idh_size;
    /* for the resources */
    GRPICONDIRHEADER *pgidh = NULL;
    WORD gidh_size;
    HANDLE hUpdate = NULL;
    int i;
    char *icodata;
    DWORD icosize;
    icodata = MapExistingFile(ico, &icosize);
    if (!icodata)
        return 0;
        
    pidh = (ICONDIRHEADER *)icodata;
    idh_size = sizeof(ICONDIRHEADER) + sizeof(ICONDIRENTRY) * pidh->idCount;

    pgidh = CreateGrpIconDirHeader(pidh, 1);
    gidh_size = sizeof(GRPICONDIRHEADER) + sizeof(GRPICONDIRENTRY) * pgidh->idCount;

	hUpdate = BeginUpdateResource(exe, FALSE);
    if (!hUpdate) goto failed;
    
    if (!UpdateResource
			( hUpdate
			, MAKEINTRESOURCE(RT_GROUP_ICON)
			, MAKEINTRESOURCE(iconResourceID)
			, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)
			, pgidh, gidh_size))	
		goto failed;
    
    for (i = 0; i < pidh->idCount; ++i) {
        char *cp = &icodata[pidh->idEntries[i].dwImageOffset];
        int cBytes = pidh->idEntries[i].dwBytesInRes;
        if (!UpdateResource
				( hUpdate
				, MAKEINTRESOURCE(RT_ICON)
				, MAKEINTRESOURCE(i+1)
				, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)
				, cp, cBytes))
            goto failed;        
    }

    free(pgidh);
    UnmapViewOfFile(icodata);

    if (!EndUpdateResource(hUpdate, FALSE))
        return 0;    
    return 1;

  failed:
    if (pgidh)
        free(pgidh);
    if (hUpdate)
        EndUpdateResource(hUpdate, TRUE);
    if (icodata)
        UnmapViewOfFile(icodata);
    return 0;
}
Example #2
0
BOOL _LoadPythonDLL(HMODULE hmod)
{
	HRSRC hrsrc;
	char *pBaseAddress;
	int size;

	if (!dirname[0])
		calc_dirname(hmod);

	// Try to locate pythonxy.dll as resource in the exe
	hrsrc = FindResource(hmod, MAKEINTRESOURCE(1), PYTHONDLL);
	if (hrsrc) {
		HGLOBAL hgbl = LoadResource(hmod, hrsrc);
		if (!_load_python(PYTHONDLL, LockResource(hgbl))) {
			SystemError(GetLastError(), "Could not load python dll");
			return FALSE;
		}
//		dprintf("Loaded pythondll as RESOURCE\n");
		return TRUE;
	}

	// try to load pythonxy.dll as bytes at the start of the zipfile
	pBaseAddress = MapExistingFile(libfilename, &size);
	if (pBaseAddress) {
		int res = 0;
		if (0 == strncmp(pBaseAddress, "<pythondll>", 11))
			res = _load_python(PYTHONDLL, pBaseAddress + 11 + sizeof(int));
		UnmapViewOfFile(pBaseAddress);
		if (res) {
//			dprintf("Loaded pythondll as <pythondll> from %s\n", libfilename);
			return TRUE;
		}
	}

	// try to load pythonxy.dll from the file system
	{
		char buffer[_MAX_PATH + _MAX_FNAME + _MAX_EXT];
		snprintf(buffer, sizeof(buffer), "%s\\%s", dirname, PYTHONDLL);

		if (!_load_python(buffer, NULL)) {
			SystemError(GetLastError(), "LoadLibrary(pythondll) failed");
			SystemError(0, buffer);
			return FALSE;
		}
//		dprintf("Loaded pythondll from file %s\n", buffer);
	}
	return TRUE;
}
Example #3
0
void _TryLoadZlib(HMODULE hmod)
{
	char *pBaseAddress;
	char *pdata;
	HRSRC hrsrc;

	// Try to locate pythonxy.dll as resource in the exe
	hrsrc = FindResource(hmod, MAKEINTRESOURCE(1), "ZLIB.PYD");
	if (hrsrc) {
		HGLOBAL hglb = LoadResource(hmod, hrsrc);
		if (hglb) {
			_Import_Zlib(LockResource(hglb));
		}
		return;
	}

	// try to load zlib.pyd from the file system
	{
		HMODULE hlib;
		char buffer[_MAX_PATH + _MAX_FNAME + _MAX_EXT];
		snprintf(buffer, sizeof(buffer), "%s\\%s", dirname, "zlib.pyd");

		hlib = LoadLibrary(buffer);
		if(hlib) {
			void (*proc)(void);
			proc = (void(*)(void))GetProcAddress(hlib, "initzlib");
			if(proc) {
				proc();
				return;
			}
		}
	}

	// try to load zlib.pyd as bytes at the start of the zipfile
	pdata = pBaseAddress = MapExistingFile(libfilename, NULL);
	if (pBaseAddress) {
		if (0 == strncmp(pBaseAddress, "<pythondll>", 11)) {
			pdata += 11;
			pdata += *(int *)pdata + sizeof(int);
		}
		if (0 == strncmp(pdata, "<zlib.pyd>", 10)) {
			pdata += 10 + sizeof(int);
			_Import_Zlib(pdata);
		}
		UnmapViewOfFile(pBaseAddress);
	}
}