Click here to Skip to main content
15,924,196 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: CFile::Remove fails Pin
David Crow20-May-10 6:18
David Crow20-May-10 6:18 
AnswerRe: CFile::Remove fails Pin
Luc Pattyn20-May-10 9:18
sitebuilderLuc Pattyn20-May-10 9:18 
GeneralRe: CFile::Remove fails Pin
Mike Osbahr25-May-10 4:54
Mike Osbahr25-May-10 4:54 
QuestionIn-place "conversion" of a string literal into a named object Pin
Code-o-mat20-May-10 4:07
Code-o-mat20-May-10 4:07 
QuestionRe: In-place "conversion" of a string literal into a named object Pin
CPallini20-May-10 11:41
mveCPallini20-May-10 11:41 
AnswerRe: In-place "conversion" of a string literal into a named object Pin
Stephen Hewitt20-May-10 14:13
Stephen Hewitt20-May-10 14:13 
AnswerRe: In-place "conversion" of a string literal into a named object Pin
Code-o-mat20-May-10 21:56
Code-o-mat20-May-10 21:56 
QuestionCalling a function directly via VTable. Pin
Green Fuze20-May-10 3:32
Green Fuze20-May-10 3:32 
Hey everybody.
I am trying to a call a virtual function directly from the VTable.

I created a COM component using the visual studio (ATL Simple object).

<br />
STDMETHODIMP Ctest_com::print_me(BSTR txt)<br />
{<br />
  OutputDebugString(txt);<br />
  return S_OK;<br />
}<br />


Now, I am trying this use the COM, but calling the function via VTable:
<br />
// signature of print_me.<br />
// STDMETHODCALLTYPE is __stdcall<br />
typedef HRESULT (STDMETHODCALLTYPE* ptr_print)(BSTR); <br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
  CoInitialize(NULL);<br />
  <br />
  cpp_com_testLib::Itest_com* comobj;<br />
  HRESULT hr = CoCreateInstance(__uuidof(cpp_com_testLib::test_com),<br />
  NULL,<br />
  CLSCTX_INPROC_SERVER,<br />
  __uuidof(cpp_com_testLib::Itest_com),<br />
  (void**)&comobj);<br />
<br />
  int* vptr = (int*)(comobj); <br />
  vptr = (int*)*vptr;  // gets a pointer to the VTABLE<br />
  int* vproc0 = (int*)vptr[0]; // get a point to first function in VTable<br />
  ...<br />
  ...<br />
  ...<br />
  int* vproc7 = (int*)vptr[7]; // pointer to print_me() !<br />
<br />
  ptr_print p = (ptr_print)vproc7; // cast to the function pointer.<br />
  _bstr_t bstr(_T("MY TEXT!"));<br />
  p(bstr); // <--- happens the problem.<br />
<br />
  comobj->Release();<br />
<br />
  CoUninitialize();<br />
<br />
  return 0;<br />
}<br />


NOW, here is THE PROBLEM.
When I call "p(bstr)" I do get to "print_me()", BUT the parameter "txt" is not passed to the function correctly (I sends a whole different address, so it is a BAD POINTER).

ANY IDEAS????
THANKS A LOT IN ADVANCE!
AnswerRe: Calling a function directly via VTable. Pin
Aescleal20-May-10 3:45
Aescleal20-May-10 3:45 
GeneralRe: Calling a function directly via VTable. Pin
Chris Meech20-May-10 4:19
Chris Meech20-May-10 4:19 
GeneralRe: Calling a function directly via VTable. Pin
Green Fuze20-May-10 6:09
Green Fuze20-May-10 6:09 
GeneralRe: Calling a function directly via VTable. Pin
Aescleal20-May-10 12:32
Aescleal20-May-10 12:32 
QuestionCreate a custom Setup tool to instal other setup programs. (hooking involved.) Pin
Natural_Demon20-May-10 3:24
Natural_Demon20-May-10 3:24 
QuestionCListCtrl Pin
Sakhalean20-May-10 2:52
Sakhalean20-May-10 2:52 
AnswerRe: CListCtrl Pin
CPallini20-May-10 3:02
mveCPallini20-May-10 3:02 
GeneralRe: CListCtrl Pin
Sakhalean20-May-10 3:38
Sakhalean20-May-10 3:38 
GeneralRe: CListCtrl Pin
josda100020-May-10 9:29
josda100020-May-10 9:29 
GeneralRe: CListCtrl Pin
Sakhalean21-May-10 2:41
Sakhalean21-May-10 2:41 
GeneralRe: CListCtrl Pin
josda100021-May-10 3:36
josda100021-May-10 3:36 
GeneralRe: CListCtrl Pin
josda100021-May-10 3:41
josda100021-May-10 3:41 
AnswerRe: CListCtrl Pin
David Crow20-May-10 9:54
David Crow20-May-10 9:54 
GeneralRe: CListCtrl Pin
josda100020-May-10 10:09
josda100020-May-10 10:09 
GeneralRe: CListCtrl Pin
David Crow20-May-10 10:27
David Crow20-May-10 10:27 
GeneralRe: CListCtrl Pin
josda100020-May-10 10:37
josda100020-May-10 10:37 
QuestionLinker Error Pin
john563220-May-10 2:20
john563220-May-10 2:20 

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.