This is my first DBP plugin that actually accesses internal DBPro stuff, but whenever I use one of the commands, it crashes.
Here is the main code:
// TestDBProAccess.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include <windows.h>
#include "Interface.h"
#include "globstruct.h"
#include "Math.h"
#include <iostream>
#include <fstream>
#include <cmath>
#include "DBOData.h"
#include <list>
#include <vector>
using namespace std;
#define EXPORT extern "C" __declspec(dllexport)
// Core pointer declaration
GlobStruct* Core=NULL;
typedef sObject* (*pfnGetObject)(int);
typedef IDirect3DTexture9* (*pfnGetImage)(int);
pfnGetObject GetDBObject = (pfnGetObject)GetProcAddress(Core->g_Basic3D,"?GetObjectA@@YAPAUsObject@@H@Z");
pfnGetImage GetDBImage = (pfnGetImage)GetProcAddress(Core->g_Image,"?GetPointer@@YAPAUIDirect3DTexture9@@H@Z");
EXPORT void ReceiveCoreDataPtr ( LPVOID Core_ )
{
Core=(GlobStruct*)Core_;
}
struct LockedImage
{
int ID;
IDirect3DSurface9* MainLayer;
D3DLOCKED_RECT* LayerData;
RECT* LockedRect;
};
int Init=0;
vector<LockedImage*> ImgArr;
EXPORT void Error(const char msg[]){
MessageBox(Core->hWnd, (LPCWSTR)msg, (LPCWSTR)"Error in DBFunctsV1.dll", MB_OK);
}
EXPORT LockedImage* GetImageArrayElement(int id){
for each (LockedImage* i in ImgArr)
{
if (i->ID == id)
return i;
}
return NULL;
}
EXPORT BYTE InterPol(BYTE a, BYTE b, BYTE c){
BYTE d = b-a;
return a+((d*c)/255);
}
EXPORT void LockImage(int id, int x, int y, int w, int h){
LockedImage* i = GetImageArrayElement(id);
if (i == NULL)
{
ImgArr.insert(ImgArr.end(), NULL);
i = ImgArr.back();
i->ID = id;
}
else
i->MainLayer->UnlockRect();
i->LockedRect->left = x;
i->LockedRect->top = y;
i->LockedRect->right = x+w;
i->LockedRect->bottom = y+h;
GetDBImage(id)->GetSurfaceLevel(0,&i->MainLayer);
i->MainLayer->LockRect(i->LayerData, i->LockedRect, 0);
}
EXPORT void UnlockImage(int id){
for (DWORD i = 0;i<ImgArr.size();i++)
{
if (ImgArr[i]->ID == id)
{
ImgArr.erase(ImgArr.begin()+i);
return;
}
}
return;
}
EXPORT DWORD GetDotImage32(int id, int x, int y){
LockedImage* i = GetImageArrayElement(id);
if (i == NULL){
Error("Image has not been locked");
return NULL;
}
DWORD* Dest = (DWORD*)i->LayerData->pBits;
Dest+=i->LayerData->Pitch*y;
Dest+=x*4;
return *Dest;
}
EXPORT DWORD GetPointerImage(int id){
LockedImage* i = GetImageArrayElement(id);
if (i == NULL){
Error("Image has not been locked");
return NULL;
}
return (DWORD)i->LayerData->pBits;
}
EXPORT DWORD GetPointerVariableSpace(){
return (DWORD)Core->g_pVariableSpace;
}
EXPORT DWORD GetDBProWindow(){
return (DWORD)Core->hWnd;
}
EXPORT DWORD GetDBProWindowIcon(){
return (DWORD)Core->hAppIcon;
}
EXPORT int GetPitchImage(int id){
LockedImage* i = GetImageArrayElement(id);
if (i == NULL){
Error("Image has not been locked");
return NULL;
}
return i->LayerData->Pitch;
}
EXPORT DWORD ImageLockedImage(int id){
LockedImage* i = GetImageArrayElement(id);
if (i == NULL){
return 0;
}
return 1;
}
EXPORT DWORD ImagesLockedImage(){
return ImgArr.size();
}
EXPORT int GetLockedImageID(DWORD id){
if (id<ImgArr.size())
return ImgArr[id]->ID;
Error("Image index outside array");
return NULL;
}
EXPORT int GetLockedAreaLeftImage(int id){
LockedImage* i = GetImageArrayElement(id);
if (i == NULL){
Error("Image has not been locked");
return NULL;
}
return i->LockedRect->left;
}
EXPORT int GetLockedAreaTopImage(int id){
LockedImage* i = GetImageArrayElement(id);
if (i == NULL){
Error("Image has not been locked");
return NULL;
}
return i->LockedRect->top;
}
EXPORT int GetLockedAreaRightImage(int id){
LockedImage* i = GetImageArrayElement(id);
if (i == NULL){
Error("Image has not been locked");
return NULL;
}
return i->LockedRect->right;
}
EXPORT int GetLockedAreaBottomImage(int id){
LockedImage* i = GetImageArrayElement(id);
if (i == NULL){
Error("Image has not been locked");
return NULL;
}
return i->LockedRect->bottom;
}
EXPORT void PutDotImage32(int id, DWORD col, int x, int y, int mode){
LockedImage* i = GetImageArrayElement(id);
if (i == NULL){
Error("Image has not been locked");
return;
}
if (x<0||y<0||x>=(i->LockedRect->right-i->LockedRect->left)||y>=(i->LockedRect->bottom-i->LockedRect->top)){
return;
}
BYTE* Dest = (BYTE*)i->LayerData->pBits;
Dest+=i->LayerData->Pitch*y;
Dest+=x*4;
DWORD Col_A = (col>>24);
DWORD Col_R = ((col<<8)>>24);
DWORD Col_G = ((col<<16)>>24);
DWORD Col_B = ((col<<24)>>24);
switch (mode)
{
case 0: //REPLACE
*(DWORD*)Dest = col;
break;
case 1: //ADD
*Dest = (BYTE)min(255,*Dest+Col_A); Dest++;
*Dest = (BYTE)min(255,*Dest+Col_R); Dest++;
*Dest = (BYTE)min(255,*Dest+Col_G); Dest++;
*Dest = (BYTE)min(255,*Dest+Col_B);
break;
case 2: //SUBTRACT
*Dest = (BYTE)max(0,*Dest-Col_A); Dest++;
*Dest = (BYTE)max(0,*Dest-Col_R); Dest++;
*Dest = (BYTE)max(0,*Dest-Col_G); Dest++;
*Dest = (BYTE)max(0,*Dest-Col_B);
break;
case 3: //AVERAGE
*Dest = (BYTE)(*Dest+Col_A)/2; Dest++;
*Dest = (BYTE)(*Dest+Col_R)/2; Dest++;
*Dest = (BYTE)(*Dest+Col_G)/2; Dest++;
*Dest = (BYTE)(*Dest+Col_B)/2;
break;
case 4: //OVERLAY
*Dest = (BYTE)min(255,*Dest+Col_A); Dest++;
*Dest = InterPol(*Dest,(BYTE)Col_R,(BYTE)Col_A); Dest++;
*Dest = InterPol(*Dest,(BYTE)Col_G,(BYTE)Col_A); Dest++;
*Dest = InterPol(*Dest,(BYTE)Col_B,(BYTE)Col_A);
break;
}
}
EXPORT void SetObjectX(int id, float x){
GetDBObject(id)->position.vecPosition.x = x;
}
EXPORT void SetObjectY(int id, float y){
GetDBObject(id)->position.vecPosition.y = y;
}
EXPORT void SetObjectZ(int id, float z){
GetDBObject(id)->position.vecPosition.z = z;
}
EXPORT DWORD ObjectScaleX(int id){
return *(DWORD*)&GetDBObject(id)->position.vecScale.x;
}
EXPORT DWORD ObjectScaleY(int id){
return *(DWORD*)&GetDBObject(id)->position.vecScale.y;
}
EXPORT DWORD ObjectScaleZ(int id){
return *(DWORD*)&GetDBObject(id)->position.vecScale.z;
}
It compiles with 0 errors, and 0 warnings in VS
Attached is the compiled dll.
Compiling code with one of the functions in the dll works, but as soon as the executable runs, I get a crash.