Click here to Skip to main content
15,891,867 members
Home / Discussions / COM
   

COM

 
GeneralRe: The interface contract Pin
Not Active27-Sep-01 6:35
mentorNot Active27-Sep-01 6:35 
GeneralRe: The interface contract Pin
In-At23-Oct-01 20:35
In-At23-Oct-01 20:35 
GeneralRe: The interface contract Pin
Andrew McGrath23-Oct-01 21:09
Andrew McGrath23-Oct-01 21:09 
GeneralRe: The interface contract Pin
In-At23-Oct-01 23:59
In-At23-Oct-01 23:59 
Questionhow to pass USER_LOGON variable to ActiveX developed in VC++? Pin
Bartek27-Sep-01 0:26
Bartek27-Sep-01 0:26 
QuestionThe initial size in the resurce editor? Pin
George26-Sep-01 21:19
George26-Sep-01 21:19 
Questionhow to transfer Interface Pointer? Pin
maya26-Sep-01 16:05
maya26-Sep-01 16:05 
GeneralNewbie, please help Pin
Rob Brown26-Sep-01 9:25
Rob Brown26-Sep-01 9:25 
Hi,

I'm a VB programmer who is trying to convert an old C console application to a C++ ATL COM DLL for use with a VB GUI.

My code basically allows the client to set a filename and then call a function which launches a private function in a seperate thread and returns immediately.

My private function then trundles along, raising events to inform the client of it's progress along the way.

All sounds good so far, unfortunately my code doesn't work, all my properties, methods, variables and so on were created by wizards.

Here is my implementation file (Asynch.cpp):

#include "stdafx.h"
#include "AsynchEg.h"
#include "Asynch.h"
// Required for _beginthread and _endthread - do not remove
#include "process.h"
#include "comdef.h"

STDMETHODIMP CAsynch::RequestNewThread()
{
// Begin a new thread and start the _NewThread function
_beginthread(_NewThread, 0, (void*)(this));
return S_OK;
}

void CAsynch::_NewThread(void* pCaller)
{
FILE *file;
BSTR wfilename;
char nfilename[256];
LPSTR filename;
// Cast the passed void pointer to a CAsynch object
CAsynch* pAsynch = (CAsynch*) pCaller;
// Convert the FileName property to a character array for use in fopen
pAsynch->get_FileName(&wfilename);
WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, wfilename, -1, nfilename, sizeof nfilename
, NULL, NULL);
filename = nfilename;
// Open the file
if((file = fopen(filename, "rb")) == 0)
{
// TODO: Raise error
}
else
{
// Close the file
fclose(file);
// Tell the calling object to raise it's ThreadDone event
pAsynch->Fire_ThreadDone();
}
// End this thread
_endthread();
}

// Returns the FileName property
STDMETHODIMP CAsynch::get_FileName(BSTR *pVal)
{
// Populate the pointer with the private variable
*pVal = m_FileName;
return S_OK;
}

// Sets the FileName property
STDMETHODIMP CAsynch::put_FileName(BSTR newVal)
{
// Copy the new value to the private variable
_bstr_t NewBSTR;
NewBSTR.Assign(newVal);
m_FileName = NewBSTR.copy();
return S_OK;
}

If I run my VB exe then I get a memory exception.

If I run the C++ end in debug then I get an access violation on the Invoke line of the Fire_ThreadDone function.

If I run VB in debug mode my code works and my event is raised.

What is going on?

If you need a copy of my projects (VC++6 and VB6) then mail me and I'll send you a copy.

Also, can anyone tell me how to raise run time errors to my VB client?

Any consttuctive criticism / advice is greatly appreciated.

Best Regards,

Rob Brown
GeneralRe: Newbie, please help Pin
Daniel Turini29-Sep-01 3:30
Daniel Turini29-Sep-01 3:30 
GeneralExport function Pin
Jose Fco Bonnin26-Sep-01 4:47
Jose Fco Bonnin26-Sep-01 4:47 
GeneralRe: Export function Pin
Not Active26-Sep-01 5:22
mentorNot Active26-Sep-01 5:22 
GeneralDCOM access denied Pin
Ali Issa25-Sep-01 1:16
Ali Issa25-Sep-01 1:16 
GeneralRe: DCOM access denied Pin
maya26-Sep-01 15:56
maya26-Sep-01 15:56 
GeneralRe: DCOM access denied Pin
Shadi Al-Kahwaji2-Oct-01 22:23
Shadi Al-Kahwaji2-Oct-01 22:23 
GeneralRe: DCOM access denied Pin
Shadi Al-Kahwaji8-Oct-01 0:33
Shadi Al-Kahwaji8-Oct-01 0:33 
Generalcomparioson of VB COM and ATL COM Pin
Ganesh Ramaswamy24-Sep-01 6:39
Ganesh Ramaswamy24-Sep-01 6:39 
GeneralRe: comparioson of VB COM and ATL COM Pin
Daniel Turini24-Sep-01 6:43
Daniel Turini24-Sep-01 6:43 
GeneralRe: comparioson of VB COM and ATL COM Pin
Amit Dey25-Sep-01 18:21
Amit Dey25-Sep-01 18:21 
GeneralRe: comparioson of VB COM and ATL COM Pin
David Salter27-Sep-01 11:11
David Salter27-Sep-01 11:11 
GeneralUnable to synchronize the data from SQL Server CE Pin
24-Sep-01 0:07
suss24-Sep-01 0:07 
Generalretrun BSTR Pin
Eran22-Sep-01 3:25
Eran22-Sep-01 3:25 
GeneralRe: retrun BSTR Pin
Aaron Schaefer24-Sep-01 5:49
Aaron Schaefer24-Sep-01 5:49 
GeneralRe: retrun BSTR Pin
Michael Dunn24-Sep-01 14:55
sitebuilderMichael Dunn24-Sep-01 14:55 
GeneralCOMAddin for Word2000 and Excel2000 Pin
Sree Ram21-Sep-01 8:55
Sree Ram21-Sep-01 8:55 
GeneralMFC CFtpFileFind CFtpConnection and timeout Pin
Amit Dey21-Sep-01 6:07
Amit Dey21-Sep-01 6:07 

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.