Pass 2D-Array by Ref/Pointer
Hi guys,
I am trying to pass a 2D Byte Array by pointer from VB 6 to C++ DLL for faster processing.
Here is the VB code i'm using:
Code:
Private Declare Function ImageBrightness Lib "ipong.dll" (ByRef lpDib As Any, uBPSL As Long, uHeight As Long, Value As Long) As Long
Private Sub Command1_Click()
Dim bDib() As Byte
ReDim bDib(5, 1)
bDib(0, 0) = 255
bDib(1, 0) = 255
bDib(2, 0) = 255
bDib(3, 0) = 0
bDib(4, 0) = 0
bDib(5, 0) = 255
bDib(0, 1) = 0
bDib(1, 1) = 255
bDib(2, 1) = 0
bDib(3, 1) = 255
bDib(4, 1) = 0
bDib(5, 1) = 0
Call ImageBrightness(bDib(0, 0), 6, 2, 0)
End Sub
And here is my c code (although the algorithm does invert not brightness)...
Code:
#include "stdafx.h"
#include "resource.h"
#include "windows.h"
#include "oleauto.h"
BOOL __declspec (dllexport) __stdcall ImageBrightness(BYTE **bDib, UINT uBPSL, UINT uHeight, UINT Value);
HINSTANCE ghInst;
int APIENTRY DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
ghInst = hModule;
return TRUE;
}
BOOL __declspec (dllexport) __stdcall ImageBrightness(BYTE **bDib, UINT uBPSL, UINT uHeight, UINT Value)
{
UINT nW, nH;
nW = uBPSL - 2;
nH = uHeight - 1;
UINT x, y, x_1, x_2;
for(x=0;x<nW;x=x+3)
{
for(y=0;y<nH;y++)
{
x_1 = x + 1;
x_2 = x + 2;
//Invert each byte
bDib[x_2][y] = 255 - bDib[x_2][y];
bDib[x_1][y] = 255 - bDib[x_1][y];
bDib[x][y] = 255 - bDib[x][y];
}
}
return true;
}
When i call the ImageBrightness function my vb executable crashes. I understand how pointers work but not completely sure how to deal with this scenario. Any help would be much appreciated.
Cheers
option