This doesn't do what you think it does:
item[i].stringresource="";
It points your 'stringresource' at a constant string. And as it's in a loop, it points all the array items at the same string.
This isn't the main source of your problem though - this is:
DLL void dr_setitemstring()
{
char text[1000];
...
item[f].stringresource=text;
You have reserved space on the stack and filled it with some characters. You then assign the address of that space to your stringresource. Then on the next loop, you overwrite those characters and then assign the same address to your stringresource.
Also, as soon as you leave that function, that stack space is no longer yours, and the address cannot be used in a valid way - but you've made many semi-permanent records of that address in your array.
Bottom line - you don't understand C strings and should find a tutorial somewhere if you want to continue to use them.
Here's some working code (rearrange to fit your structure) using C strings:
#define DLL extern "C" __declspec (dllexport)
#define DLLNOC __declspec (dllexport)
#include "globstruct.h"
struct iteminfo
{
bool exist; //irrelevant
unsigned short int type; //irrelevant
int resource; //irrelevant
LPSTR stringresource; //THIS IS A POINTER TO THE LOCATION WHERE THE STRING CONTENT IS STORED. IT IS *NOT* A STRING!
int name; //irrelevant
};
iteminfo *item;
GlobStruct *g_pGlob=NULL;
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <string.h>
//#include "main.h"
DLL void dr_start()
{
item=new iteminfo[500];
for(int i=0;i<500;i++)
{
item[i].exist=0;
item[i].type=0;
item[i].resource=0;
item[i].stringresource=0; // Point at nothing.
item[i].name=0;
}
}
DLL void dr_setitemstring()
{
for(int f=0;f<10;f++)
{
char* text = new char[1000]; // The size is overkill, but keeps the example simple.
sprintf(text,"This is non-working string number %i",f);
delete[] item[f].stringresource; // Delete the original string (safe to delete a null pointer).
item[f].stringresource=text; // Now assign the string
MessageBox(0,item[f].stringresource,"FIRST",0);
}
for(int s=0;s<10;s++)
{
MessageBox(0,item[s].stringresource,"SECOND",0);
}
}
Here's the same code changed slightly to use the C++ std::string class:
#define DLL extern "C" __declspec (dllexport)
#define DLLNOC __declspec (dllexport)
#include "globstruct.h"
#include <string>
struct iteminfo
{
bool exist; //irrelevant
unsigned short int type; //irrelevant
int resource; //irrelevant
std::string stringresource; // THIS *IS* A STRING!
int name; //irrelevant
};
iteminfo *item;
GlobStruct *g_pGlob=NULL;
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <string.h>
//#include "main.h"
DLL void dr_start()
{
item=new iteminfo[500];
for(int i=0;i<500;i++)
{
item[i].exist=0;
item[i].type=0;
item[i].resource=0;
item[i].stringresource=""; // This works, because the string class copies the target string data into itself.
item[i].name=0;
}
}
DLL void dr_setitemstring()
{
char text[1000];
for(int f=0;f<10;f++)
{
sprintf(text,"This is non-working string number %i",f);
item[f].stringresource=text; // Now copy the target string data into the string
MessageBox(0,item[f].stringresource.c_str(),"FIRST",0); // c_str() is how you get an LPSTR from a std::string, but the pointer is only temporary
}
for(int s=0;s<10;s++)
{
MessageBox(0,item[s].stringresource.c_str(),"SECOND",0);
}
}