HMODULE g_hModule = GetModuleHandle( 0 );
HRSRC	hRes		= FindResource( g_hModule, MAKEINTRESOURCE( ID_DLL_MYDLL ), "ID_DLL" );
HGLOBAL hResource	= LoadResource( g_hModule, hRes );
DWORD	iResSize	= SizeofResource( g_hModule, hRes );
BYTE* pData 		= ( BYTE* )LockResource( hResource );

When I included a dll file into my project, I used:

fstream pFile( ".\\My Dll.dll", ios::out );
pFile.write( ( const char* )pData, iResSize );

So that It creates the dll outside of the executable at run time.

But ive noticed that the dll fails to be properly written and the file size is out of sync

2.04 MB (2,145,280 bytes) For original dll

2.04 MB (2,146,101 bytes) For the dll that was written

What could be causing this?

6 Years
Discussion Span
Last Post by mike_2000_17

First, is the external DLL file working?

Second, maybe you should open the file with ios::binary flag as well. Maybe, I'm completely wrong though, I'm not expert on file systems. I can only suspect it is some sort of file header information

Third, are those file sizes obtained from the "properties" popup thing, or did you make a little program to open both, seek the end, and see if their sizes match. Maybe that's useless, I just don't trust Windows to do even the simplest thing correctly.

Finally, did you try and check what the difference between the files are (in linux you would use the "diff" command, don't know in windows). Most probably the difference has to be localized, i.e. only at the start or the end would make some sense.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.