Click here to Skip to main content
15,910,211 members
Home / Discussions / COM
   

COM

 
AnswerRe: EXCEL - Hooking Excel VTABLE Pin
jaafar tribak17-Apr-15 13:59
jaafar tribak17-Apr-15 13:59 
QuestionHow to generate an early-bound COM object in VS2013 Pin
CrewR4-Mar-15 6:50
CrewR4-Mar-15 6:50 
SuggestionHow to reference IWshRuntimeLibrary Pin
ThanhTrungDo2-Mar-15 17:24
professionalThanhTrungDo2-Mar-15 17:24 
GeneralRe: How to reference IWshRuntimeLibrary Pin
Richard MacCutchan2-Mar-15 21:27
mveRichard MacCutchan2-Mar-15 21:27 
QuestionRegistration Free COM / COM Interop Pin
Michael Salzlechner8-Feb-15 3:28
Michael Salzlechner8-Feb-15 3:28 
AnswerRe: Registration Free COM / COM Interop Pin
F-ES Sitecore2-Mar-15 4:55
professionalF-ES Sitecore2-Mar-15 4:55 
GeneralRe: Registration Free COM / COM Interop Pin
DriveByCoder24-Mar-15 7:18
professionalDriveByCoder24-Mar-15 7:18 
GeneralRe: Registration Free COM / COM Interop Pin
F-ES Sitecore24-Mar-15 8:12
professionalF-ES Sitecore24-Mar-15 8:12 
QuestionHow to SubClass ContentControl in MSWORD Pin
Member 1017975812-Dec-14 16:07
Member 1017975812-Dec-14 16:07 
QuestionDCOM CLASSNOTREG error Pin
Billy Bang19-Nov-14 18:58
Billy Bang19-Nov-14 18:58 
AnswerRe: DCOM CLASSNOTREG error Pin
Richard MacCutchan19-Nov-14 21:29
mveRichard MacCutchan19-Nov-14 21:29 
GeneralRe: DCOM CLASSNOTREG error Pin
Billy Bang19-Nov-14 21:48
Billy Bang19-Nov-14 21:48 
GeneralRe: DCOM CLASSNOTREG error Pin
Richard MacCutchan19-Nov-14 22:49
mveRichard MacCutchan19-Nov-14 22:49 
QuestionHow to remove other submenu items when implement my context menu handle. Pin
chiyun11-Sep-14 20:39
chiyun11-Sep-14 20:39 
QuestionC# COM Server should be called by a C++ client... Pin
Juergen_8027-Aug-14 1:44
Juergen_8027-Aug-14 1:44 
SuggestionRe: C# COM Server should be called by a C++ client... Pin
Richard MacCutchan27-Aug-14 2:09
mveRichard MacCutchan27-Aug-14 2:09 
GeneralRe: C# COM Server should be called by a C++ client... Pin
Juergen_8027-Aug-14 2:27
Juergen_8027-Aug-14 2:27 
QuestionCreating an Access Add-In that can be used by all users - "Connect" error Pin
lmaycock8-Aug-14 3:04
lmaycock8-Aug-14 3:04 
Questioncapture Event in ActiveX component Pin
pablogvivo28-Jul-14 4:28
pablogvivo28-Jul-14 4:28 
Questionerror in an example of loading dll dynamically Pin
virusx198416-Jul-14 4:41
virusx198416-Jul-14 4:41 
In the "Dynamic Selection of a Component" section of the book <com+ programming="" -="" a="" practical="" guide="" using="" visual="" c++="" and="" atl="">, there is an example teach me to load dll dynamically. Here is my code:

It couldn't run. I guess error in the file "tv.cpp". This code couldn't return a function pointer(I print the value of proc, and computer shows that proc = 0): "CREATEVCRPROC proc = reinterpret_cast<createvcrproc>(GetProcAddress(h, "CreateVcr"));" Confused | :confused:

PS: I use Microsoft C++ Compiler to compile this files
> cl -c tv.cpp
> cl -c vcr.cpp
> link -dll vcr.obj
> link tv.obj

Could anyone help me? Thank you very much!!

C++
// file: vcr.h

#include "video.h"

class CVcr : public IVideo{
	
public:
	CVcr(void);
	long _stdcall GetSignalValue();
	void _stdcall Delete();
	
private:
	long m_lCurValue;
	int m_nCurCount;
};


C++
// file: vcr.cpp

#include "vcr.h"

CVcr::CVcr(){
	m_lCurValue = 5;
	m_nCurCount = 0;
}

long CVcr::GetSignalValue(){
	
	m_nCurCount++;
	if(5 == m_nCurCount){
		m_lCurValue = 5;
		m_nCurCount = 1;
	}
	
	long lReturnValue = m_lCurValue;
	m_lCurValue += 10;
	return lReturnValue;

}

IVideo * _stdcall CreateVcr(void){
	
	return new CVcr;
}

void CVcr::Delete(){
	
	delete this;
}


C++
// file: video.h - Definition of interface IVideo


class IVideo{
	
public:

	virtual long _stdcall GetSignalValue() = 0;
	virtual void _stdcall Delete() = 0;
	
};

extern "C" IVideo * _stdcall CreateVcr();


C++
// file: tv.cpp

#include "video.h"
#include <iostream> 
#include <windows.h>
using namespace std;

IVideo * CreateInstance(char * pszDll){
	
	// Define a pointer to prototype of CreateVcr function
	typedef IVideo * (_stdcall * CREATEVCRPROC)(void);
	
	// Load the specified library
	HINSTANCE h = LoadLibrary(pszDll);
	
	// Obtain the procedure entry point for CreateVcr
	CREATEVCRPROC proc = reinterpret_cast<CREATEVCRPROC>(GetProcAddress(h, "CreateVcr"));
	
	printf("proc = %d", proc);
	
	// Execute "CreateVcr" indirectly
	return (*proc)();
		
}


int main(int argc, char* argv[]) 
{
	int i; 
	IVideo * pVideo = CreateInstance("vcr.dll");

	for(i=0; i<10; i++) {
		long val = pVideo->GetSignalValue(); 
		cout << "Round: " << i << " - Value: " << val << endl; 
	} 
	
	pVideo->Delete();
	
	return 0; 
} 

AnswerRe: error in an example of loading dll dynamically Pin
Richard MacCutchan16-Jul-14 5:49
mveRichard MacCutchan16-Jul-14 5:49 
QuestionHow to simulate click event on IHtmlObjectElement in C++? Pin
FoxBryant10-Jul-14 0:55
FoxBryant10-Jul-14 0:55 
QuestionCOM using pure c++ Pin
Member 989964421-Jun-14 20:12
Member 989964421-Jun-14 20:12 
AnswerRe: COM using pure c++ Pin
Derek Tortonian28-Jun-14 8:37
Derek Tortonian28-Jun-14 8:37 
GeneralRe: COM using pure c++ Pin
Member 989964429-Jun-14 7:21
Member 989964429-Jun-14 7:21 

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.