Click here to Skip to main content
15,860,861 members
Home / Discussions / COM
   

COM

 
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 
GeneralRe: COM using pure c++ Pin
Derek Tortonian5-Aug-14 11:54
Derek Tortonian5-Aug-14 11:54 
QuestionCOMException, error code :80040154 Pin
orélle15-Jun-14 21:58
orélle15-Jun-14 21:58 
AnswerRe: COMException, error code :80040154 Pin
Richard MacCutchan15-Jun-14 23:42
mveRichard MacCutchan15-Jun-14 23:42 
GeneralRe: COMException, error code :80040154 Pin
orélle16-Jun-14 23:15
orélle16-Jun-14 23:15 
GeneralRe: COMException, error code :80040154 Pin
Richard MacCutchan16-Jun-14 23:21
mveRichard MacCutchan16-Jun-14 23:21 
GeneralRe: COMException, error code :80040154 Pin
orélle16-Jun-14 23:38
orélle16-Jun-14 23:38 
GeneralRe: COMException, error code :80040154 Pin
Richard MacCutchan17-Jun-14 0:16
mveRichard MacCutchan17-Jun-14 0:16 
GeneralRe: COMException, error code :80040154 Pin
orélle17-Jun-14 3:12
orélle17-Jun-14 3:12 
AnswerRe: COMException, error code :80040154 Pin
Anup Kasat9-Feb-15 2:12
Anup Kasat9-Feb-15 2:12 
QuestionIFileSaveDialog / Filename using C++ Pin
jung-kreidler5-Jun-14 20:03
jung-kreidler5-Jun-14 20:03 
SuggestionRe: IFileSaveDialog / Filename using C++ Pin
Richard MacCutchan5-Jun-14 22:23
mveRichard MacCutchan5-Jun-14 22:23 
GeneralRe: IFileSaveDialog / Filename using C++ Pin
jung-kreidler23-Jun-14 21:17
jung-kreidler23-Jun-14 21:17 

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.