int iSaveFileToDisk(int tnResource, char* tcPath, char* tcFilename) { PROCESS_INFORMATION lpi; STARTUPINFO si; SIZE_T lnLength, lnNumread; bool llResult; TCHAR* rptr; HRSRC hrsrc; DWORD lnSize, errorNumber; HGLOBAL glob; void* dptr; FILE* lfh; char buffer[MAX_PATH + 1]; // Make sure the resource exists rptr = MAKEINTRESOURCE(tnResource); hrsrc = FindResource(ghInstance, rptr, _T("FILES")); if (hrsrc) { // Find out its size lnSize = SizeofResource(ghInstance, hrsrc); // Load it into a global glob = LoadResource(ghInstance, hrsrc); if (glob) { // Lock it so we can read it (gets a pointer to it) dptr = LockResource(glob); if (dptr) { // Initialize the filename memset(gcCurrentFileBuffer, 0, sizeof(gcCurrentFileBuffer)); // Append the path lnLength = strlen(tcPath); memcpy(gcCurrentFileBuffer, tcPath, lnLength); // Append the trailing \ to the path/directory if needed if (gcCurrentFileBuffer[lnLength - 1] != '\\') { gcCurrentFileBuffer[lnLength] = '\\'; ++lnLength; } // Copy the filename portion memcpy(gcCurrentFileBuffer + lnLength, tcFilename, strlen(tcFilename)); // Write the file to disk // Create the file lfh = fopen(gcCurrentFileBuffer, "wb+"); if (lfh) { // We're good so far, write to it // Write with feedback during the write lnNumread = iWriteBufferToDiskWithFeedback((char*)dptr, lnSize, lfh); fclose(lfh); if (lnNumread == lnSize) { // We're good! llResult = true; } else { // Not so much llResult = false; } } else { // No good llResult = false; // Fall through } // Regardless if successful or not, we need to unlock the resource UnlockResource(glob); } } } }>Hi Folks.
>Local lcFolder >m.lcFolder = Justpath(Sys(16)) >Set Default To (m.lcFolder) > >* Init Vfp2c32 >Set Library To vfp2c32 > >#INCLUDE vfp2c.h >If !InitVFP2C32(VFP2C_INIT_ALL) > Local laError[1], lnCount, xj, lcError > lnCount = AERROREX('laError') > lcError = 'VFP2C32 Library initialization failed:' + Chr(13) > For xj = 1 To lnCount > lcError = lcError + ; > 'Error No : ' + Transform(laError[1]) + Chr(13) + ; > 'Function : ' + laError[2] + Chr(13) + ; > 'Message : "' + laError[3] + '"' > Endfor > && show/log error and abort program initialization .. > Messagebox(m.lcError,16,"Error") > Return >Endif > >#Define LOAD_LIBRARY_AS_IMAGE_RESOURCE 0x00000020 >#Define LOAD_LIBRARY_AS_DATAFILE 0x00000002 > >* http://msdn.microsoft.com/en-us/library/windows/desktop/ms684179%28v=vs.85%29.aspx >Declare Integer LoadLibraryEx In Win32api ; > String lpFileName, ; > Integer hFile, ; > Integer dwFlags > >* http://msdn.microsoft.com/en-us/library/windows/desktop/ms683152%28v=vs.85%29.aspx >Declare Integer FreeLibrary In Win32api ; > Long hModule > >Local lcResourceFile, lnhModule >m.lcResourceFile = Addbs(m.lcFolder) + "Office2007.dll" > >m.lnhModule = LoadLibraryEx(m.lcResourceFile, 0, LOAD_LIBRARY_AS_IMAGE_RESOURCE + LOAD_LIBRARY_AS_DATAFILE) >If m.lnhModule > 0 > > * > Local lcResources, laResourceTypes[1], lnResourceType, laResources[1], lnResource > m.lcResources = "" > If AResourceTypes("laResourceTypes", m.lnhModule) > 0 > For m.lnResourceType=1 To Alen(m.laResourceTypes) > m.lcResources = m.lcResources + Chr(13) + Chr(10) + ; > "Resource type: " + ; > Alltrim(Transform(m.laResourceTypes[m.lnResourceType])) + ; > Chr(13) + Chr(10) > If AResourceNames("laResources", m.lnhModule, m.laResourceTypes[m.lnResourceType]) > 0 > For m.lnResource=1 To Alen(m.laResources) > m.lcResources = m.lcResources + ; > "Resource name: " + ; > Alltrim(Transform(m.laResources[lnResource])) + ; > Chr(13) + Chr(10) > * Save each resource here... > Endfor > Endif > Endfor > _Cliptext = m.lcResources > Endif > * > > If FreeLibrary(m.lnhModule) <> 0 > Else > ? "Error releasing library..." > Endif >Else > ? "Error loading library..." >Endif > >Release Library vfp2c32 > >Clear Dlls LoadLibraryEx >Clear Dlls FreeLibrary >