Click here to Skip to main content
15,905,508 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: set back ground color for main frame in SDI Pin
gurucplusplus24-Apr-07 13:25
gurucplusplus24-Apr-07 13:25 
QuestionThe big leap to Vista and Visual Studio 2005 Pin
hcatech24-Apr-07 6:07
hcatech24-Apr-07 6:07 
AnswerRe: The big leap to Vista and Visual Studio 2005 Pin
David Crow24-Apr-07 6:18
David Crow24-Apr-07 6:18 
AnswerRe: The big leap to Vista and Visual Studio 2005 Pin
Michael Dunn24-Apr-07 8:35
sitebuilderMichael Dunn24-Apr-07 8:35 
GeneralRe: The big leap to Vista and Visual Studio 2005 Pin
hcatech25-Apr-07 3:48
hcatech25-Apr-07 3:48 
GeneralRe: The big leap to Vista and Visual Studio 2005 Pin
Michael Dunn25-Apr-07 13:52
sitebuilderMichael Dunn25-Apr-07 13:52 
AnswerRe: The big leap to Vista and Visual Studio 2005 Pin
cp987624-Apr-07 17:51
cp987624-Apr-07 17:51 
QuestionDLL CRuntimeClass Pointers Differ From App [modified] Pin
Peter Saint24-Apr-07 6:04
Peter Saint24-Apr-07 6:04 
Hi,

What do I need to do so that the CRuntimeClass addresses known to my Regular DLL correspond to the CRuntimeClass addresses known to a CObject-derived object passed to the DLL from an application?

Here's the details of my problem (forgive the verbosity)...

I needed to control access to an object used by multiple threads. I used the Microsoft-documented CMutex/CSingleLock approach. Here's what my object class sort of looks like:

class MyThreadSafeResource
{
public:
MyThreadSafeResource(CString dllFileName);
void start();
void someMethod();
private:
static UINT run(LPVOID p);
CMutex m_lock;
HINSTANCE m_dll;
};

MyThreadSafeResource::MyThreadSafeResource(CString dllFileName)
{
// Load the passed DLL.

m_dll = ::LoadLibrary(dllFileName);
}

void MyThreadSafeResource::start()
{
CSingleLock singleLock(&m_lock);
singleLock.Lock();

// Spawn a worker thread

::AfxBeginThread(run, this);
}

void MyThreadSafeResource::someMethod()
{
CSingleLock singleLock(&m_lock); // POINT X
singleLock.Lock();
...
}

UINT MyThreadSafeResource::run(LPVOID)
{
MyThreadSafeResource* resource = (MyThreadSafeResource*)p;

// Call the function exposed by the DLL.

typedef void (*ExternalFunction)(LPVOID p);
ExternalFunction dllFunc = (ExternalFunction)::GetProcAddress(m_dll, "dllFunc");
dllFunc(resource);
return 0;
}

Here's what my exported DLL function sort of looks like:

extern "C"
{
__declspec(dllexport) bool dllFunc(LPVOID p)
{
MyThreadSafeResource* resource = (MyThreadSafeResource*)p;
resource->someMethod();
...
}
}

From my application's main thread I create a new instance of my resource class and "start" it:

MyThreadSafeResource resource = new MyThreadSafeResource("C:\TEMP\MYDLL.DLL");
resource->start();

At first, everything goes well... my resource object loads the DLL successfully, in the "start" method my worker thread is created successfully, my object is passed to the worker thread successfully, the worker thread calls the function within my DLL successfully, my object is passed to the DLL function successfully.

Its when the DLL function calls a method in my passed object that things go bad. My application abends at "POINT X" with the following message:

Unhandled exception at 0x00643185 in MyApplication.exe: 0xC0000005:
Access violation reading location 0x00c85edc.

It appears that the called method's CSingleLock construction is failing when it tries to ensure that the passed CMutex object is derived from CSyncObject. Here's the call stack at the time of failure:

MyDll.dll!CRuntimeClass::IsDerivedFrom(const CRuntimeClass * pBaseClass=0x101a1e9c) Line 174 C++
MyDll.dll!CObject::IsKindOf(const CRuntimeClass * pClass=0x101a1e9c) Line 45 C++
MyDll.dll!CSingleLock::CSingleLock(CSyncObject * pObject=0x00b87878, int bInitialLock=0) Line 90 + 0xd C++
MyDll.dll!MyThreadSafeResource::someMethod() Line 126 + 0x11 C++
MyDll.dll!dllFunc(void * p=0x00b87830) Line 52 + 0x8 C++
MyApplication.exe!MyThreadSafeResource::run(void * p=0x00b87830) Line 238 + 0x9 C++
MyApplication.exe!_AfxThreadEntry(void * pParam=0x0012f194) Line 114 + 0xd C++
MyApplication.exe!_threadstartex(void * ptd=0x00b87a58) Line 241 + 0xd C
kernel32.dll!7c80b683()

Any thoughts? Any and all help appreciated.

Thanks!

Peter
AnswerRe: DLL CRuntimeClass Pointers Differ From App Pin
Mark Salsbery24-Apr-07 7:59
Mark Salsbery24-Apr-07 7:59 
AnswerRe: DLL CRuntimeClass Pointers Differ From App [modified] Pin
Peter Saint24-Apr-07 8:32
Peter Saint24-Apr-07 8:32 
GeneralRe: DLL CRuntimeClass Pointers Differ From App Pin
Mark Salsbery24-Apr-07 8:55
Mark Salsbery24-Apr-07 8:55 
Questionplease help me(Networking)?!!! Pin
dSolariuM24-Apr-07 4:42
dSolariuM24-Apr-07 4:42 
QuestionRe: please help me(Networking)?!!! Pin
David Crow24-Apr-07 4:52
David Crow24-Apr-07 4:52 
QuestionAppropriate file buffer size Pin
Dustin Henry24-Apr-07 4:30
Dustin Henry24-Apr-07 4:30 
QuestionRe: Appropriate file buffer size Pin
David Crow24-Apr-07 4:32
David Crow24-Apr-07 4:32 
AnswerRe: Appropriate file buffer size Pin
Dustin Henry24-Apr-07 4:46
Dustin Henry24-Apr-07 4:46 
QuestionRe: Appropriate file buffer size Pin
David Crow24-Apr-07 4:50
David Crow24-Apr-07 4:50 
AnswerRe: Appropriate file buffer size Pin
Dustin Henry24-Apr-07 4:55
Dustin Henry24-Apr-07 4:55 
GeneralRe: Appropriate file buffer size Pin
David Crow24-Apr-07 5:02
David Crow24-Apr-07 5:02 
QuestionRe: Appropriate file buffer size Pin
Dustin Henry24-Apr-07 5:05
Dustin Henry24-Apr-07 5:05 
AnswerRe: Appropriate file buffer size Pin
David Crow24-Apr-07 5:16
David Crow24-Apr-07 5:16 
GeneralRe: Appropriate file buffer size Pin
Dustin Henry24-Apr-07 5:22
Dustin Henry24-Apr-07 5:22 
Questionbrain dead question : CFileDialog initial Dir. Pin
Maximilien24-Apr-07 4:01
Maximilien24-Apr-07 4:01 
AnswerRe: brain dead question : CFileDialog initial Dir. Pin
Dustin Henry24-Apr-07 4:24
Dustin Henry24-Apr-07 4:24 
GeneralRe: brain dead question : CFileDialog initial Dir. Pin
CPallini24-Apr-07 4:33
mveCPallini24-Apr-07 4:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.