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 );
	
pFile.close();

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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.