dirtyb15 wrote:
> Okay, here is my problem. I wrote a dll file that interfaces my
> labview program with an executable made in c++ via shared memory. All
> i am doing is reading shared memory created by the executable.
> Everything works fine for about an hour then labview crashes saying
> there was a memory error. I cannot figure out what is going on.
> Attached is my vi ,and source code for the dll. Any ideas???????
It's very simple! Each time you call the function you open a new handle
to the shared memory file without ever closing them. After some time
Windows runs out of handles and returns an error but you neverthless try
to map that handle to a pointer, which will result in returning a NULL
pointer. Then you reference that NULL pointer to fill in your info.
Attached code should give you an idea how to do it instead!
BUMMM!!
Rolf Kalbermatter
/* Call Library source file */
#include "extcode.h"
#include "cvilvsb.h"
#include "fundtypes.h"
#include "hosttype.h"
#include "platdefines.h"
#include
#include
#include
#include
#include
#include
static HANDLE ghMapObject = NULL;
extern "C"{
_declspec(dllexport) DWORD SharedMemoryInit(float *x1);
_declspec(dllexport) DWORD SharedMemoryClose(void);
}
_declspec(dllexport) DWORD SharedMemoryInit(float *x1)
{
float *MapView;
//share memory file init
if (!ghMapObject)
ghMapObject = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE,
"rstk_shared_memory");
if (ghMapObject)
{
MapView = (float*)MapViewOfFile(ghMapObject,
FILE_MAP_ALL_ACCESS, 0, 0, 0);
if (MapView)
{
CopyMemory(x1, MapView, 40 * sizeof(float));
UnmapViewOfFile(MapView);
return (0);
}
else
return GetLastError();
}
else
return GetLastError();
}
_declspec(dllexport) DWORD SharedMemoryClose(void)
{
if (ghMapObject)
{
CloseHandle(ghMapObject);
ghMapObject = NULL;
}
return (0);
}
Rolf Kalbermatter
My Blog 
DEMO, Electronic and Mechanical Support department, room 36.LB00.390