Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

krakrazor

Complicated problem

This topic is 5325 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here we go, i''ll try to explain it as good as i can! This is the function that sets up my struct as a class
CFS_API HRESULT  GetCFSIOInterface(i_CFSio ** pInterface)
{
   if(!*pInterface)
   {
      *pInterface= new c_CFSio;
      return S_OK;
   }
   return E_FAIL;
};
This is the function I use to open my DLL files:
i_CFSio *LoadCFSio(HINSTANCE hCFSioDLL)
{
	GETINTERFACE    pfnGet=0; //pointer to function

	i_CFSio * pInterface  =0; //pointer to struct

	
	hCFSioDLL = ::LoadLibrary("CFSio.dll");
	
	if(hCFSioDLL != NULL)
	{
		//Get the functions address

		pfnGet= (GETINTERFACE)::GetProcAddress(hCFSioDLL,"GetCFSIOInterface");
		
		//Release Dll if we werent able to get the function

		if(pfnGet == 0)   
		{
			::FreeLibrary(hCFSioDLL);
			return 0;
		}
		
		//Call the Function

		HRESULT hr = pfnGet(&pInterface);
		
		//Release if it didnt work

		if(FAILED(hr))   
		{   
			::FreeLibrary(hCFSioDLL);
			return 0;
		}
	}

	return pInterface; 
}
This is how i open my files:
h_file = CreateFile(filename, DesiredAccess, ShareMode, NULL, CREATE_ALWAYS, FlagsAndAttributes, NULL);
		if(h_file != INVALID_HANDLE_VALUE)
		{
			laste = GetLastError();
			if(laste == ERROR_ALREADY_EXISTS)
			{
				e_laste = CFSE_IO_OVERWRITTEN;
				b_ready = TRUE;
				goto ENDCFSio;
			}
			else
			{
				e_laste = CFSE_IO_CREATEDNEWFILE;
				b_ready = TRUE;
				goto ENDCFSio;
			}
		}
This is my shared .h definition of the class objects in my DLL.
struct i_CFSio
{
	virtual void CreateClass(LPCTSTR filename, DWORD desiredaccess, DWORD sharemode, DWORD creationdisposition, DWORD flagsandattributes) = 0;
	virtual void InitClass(LPCTSTR filename, DWORD desiredaccess, DWORD sharemode, DWORD creationdisposition, DWORD flagsandattributes) = 0;
	virtual void InitClassRead(LPCTSTR filename) = 0;
	virtual void InitClassWriteA(LPCTSTR filename) = 0;
	virtual void InitClassWriteN(LPCTSTR filename) = 0;
	virtual void DeleteClass(void) = 0;
	virtual CFSERROR GetLastIOError() = 0;
	virtual CFSERROR Write(LPCVOID buffer, DWORD len, LPDWORD written) = 0;
};
This is the actaul DLL''s internal .h file:
	void CreateClass(LPCTSTR filename, DWORD desiredaccess, DWORD sharemode, DWORD creationdisposition, DWORD flagsandattributes);
	/* ------------------------ */
	

	/* Generic file openers operations */
	void InitClass(LPCTSTR filename, DWORD desiredaccess, DWORD sharemode, DWORD creationdisposition, DWORD flagsandattributes)	{
		CreateClass(filename, desiredaccess, sharemode, creationdisposition, flagsandattributes);
	};
	
	void InitClassRead(LPCTSTR filename) {
		CreateClass(filename, GENERIC_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL);
	};

	void InitClassWriteA(LPCTSTR filename) {
		CreateClass(filename, GENERIC_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL);
	};

	void InitClassWriteN(LPCTSTR filename) {
		CreateClass(filename, GENERIC_WRITE, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL);
	};
	/* ------------------------ */


	void DeleteClass(void);

	CFSERROR GetLastIOError() { return e_laste; };

	CFSERROR Write(LPCVOID buffer, DWORD len, LPDWORD written);
And here is all of the stuff used:
	i_CFSio *iCFSio = 0;
	iCFSio = LoadCFSio(hCFSioDLL);
	iCFSio->InitClassWriteA("c:/test.txt");
	iCFSio->Write("Hello! i am me", 10, &written);
	iCFSio->DeleteClass();
This is my struct right at the crash. iCFSio 0x009903c0 __vfptr 0x1002c01c [0] 0x10001014 [1] 0x1000101e [2] 0x10001019 [3] 0x10001032 [4] 0x10001037 [5] 0x10001023 [6] 0x10001046 all that info.. now lets get to the point... my problem is that when i call "iCFSio->Write" i get a sharing violation. as you can see there are 8 functions defined in the shared .h but there are only 7 in iCFSio at runtime. What am i doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
damn! this is one of those things where i was missing something really minor and it messed everything up! i forgot to copy the newly compiled DLL file to the directory of the EXE

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!