8000 Didn't work with virtual functions · Issue #118 · fancycode/MemoryModule · GitHub
[go: up one dir, main page]

Skip to content
Didn't work with virtual functions #118
Open
@xkcd50

Description

@xkcd50

I'm using the latest version 5f83e41
and VS2022.
to reproduce this issue,please add a file ISampleDLL.h in SampleDLL dir:

#pragma once

class ISampleDLL
{
public:
	virtual ~ISampleDLL() = default;
	virtual int addNumbers(int a,int b) = 0;
};

and replace SampleDLL.h

#include "ISampleDLL.h"
class SampleDLL: public ISampleDLL
{
public:
	static SampleDLL& Instance();
	
	virtual int addNumbers(int a,int b) override;
private:
	SampleDLL();
	~SampleDLL();
	SampleDLL(const SampleDLL&) = delete;
	SampleDLL& operator=(const SampleDLL&) = delete;
};

SampleDLL.cpp

#include "SampleDLL.h"

SampleDLL::SampleDLL()
{}

SampleDLL::~SampleDLL()
{}

SampleDLL& SampleDLL::Instance()
{
	static SampleDLL instance;
	return instance;
}

int SampleDLL::addNumbers(int a,int b)
{
	return a + b;
}

extern "C" __declspec(dllexport) ISampleDLL* CreateSampleDLL()
{
	return &SampleDLL::Instance();
}

edit DllLoader.cpp

...
#include "../SampleDLL/ISampleDLL.h"
...
void LoadFromMemory(void)
{
...
        using GetSampleDLL=ISampleDLL* (*)();
        //addNumber = (addNumberProc)MemoryGetProcAddress(handle, "addNumbers");
        GetSampleDLL getSampleDLL = (GetSampleDLL)MemoryGetProcAddress(handle,"CreateSampleDLL");
        ISampleDLL* sampleDLL = getSampleDLL();
        _tprintf(_T("From memory: %d\n"), sampleDLL->addNumbers(1, 2));
...
}

then variable getSampleDLL and sampleDLL have not null address,but the vftable of sampleDLL got adress 0x0.

ps. I have read issue#31 but it didn't solve my problem

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0