accessing long pointer safearray structure in dll
hello friends,
i am debugging a dll file for an application and i am getting some problem in accessing the safearray structure in the dll file.
the application wes developed in vc++ 2005 now upgrading it to vc++2008.
For the front end there using vb script 2005.
so the problem is i am passing a structure type array (that is having data fatched from the ole database) to a dll as a LPSAFEARRAY parameter,when i executing the front end, the dll is accessing properly but when its going to allocate the memory its sending the error report (other memkry corrupted) from the backend. but when i compiling the backend dll its not giving any error.and when i trace the each and every line of the dll from the front end got to know that the problem is while its allocating the memory. i am giving a few details of the coding please someone help me to figure this out.
vb code ::
Code:
structure configtable
public pid as long
public configid as long
public wordno as long
public unit as string
public maxval as single
end structure
declearation of array in vb::
Code:
public para() as configtable
calling the dll function in vc++ ::
Code:
databaseinitialization(para,apppath)
the structure in dll::
Code:
typedef struct
{
int pid;
int configid;
int wordno;
LPVOID unit;
float maxval;
}PARAMETERS;
function where i got the error ::
Code:
databaseinitialization(LPSAFEARRAY FAR *prtPARAMDATA, LPSTR path)
{
PARAMETERS *paraTABLE;
paraTABLE=(PARAMETERS*) malloc (sizeof(PARAMETERS) * (*ptrPARAMDATA)->rgsabound->cElements); //the error line
}
i have also tried by giving like but den its givig some while compiling the dll:
Code:
paraTABLE=(PARAMETERS*) malloc (sizeof(PARAMETERS) * (*ptrPARAMDATA).rgsabound[0].cElements);
or
Code:
paraTABLE=(PARAMETERS*) malloc (sizeof(PARAMETERS) * ptrPARAMDATA->rgsabound->cElements);
but den its showing :
Code:
error C2227:left of '->rgsabound' must point to class/struct/union/generic type.
error C2227:left of '->cElements' must point to class/struct/union/generic type.
full code is not given but this line in the databaseinitialization is not executing.waiting for reply...
Re: accessing long pointer safearray structure in dll
Please, use Code tags while posting code snippets. Otherwise your code becomes absolutely unreadable! See the Announcement: Before you post....
Why do you use malloc in c++ code?
Why don't you use SafeArrayAllocData?
Re: accessing long pointer safearray structure in dll
hello friends,
i am debugging a dll file for an application and i am getting some problem in accessing the safearray structure in the dll file.
the application wes developed in vc++ 2005 now upgrading it to vc++2008.
For the front end there using vb script 2005.
so the problem is i am passing a structure type array (that is having data fatched from the ole database) to a dll as a LPSAFEARRAY parameter,when i executing the front end, the dll is accessing properly but when its going to allocate the memory its sending the error report (other memkry corrupted) from the backend. but when i compiling the backend dll its not giving any error.and when i trace the each and every line of the dll from the front end got to know that the problem is while its allocating the memory. i am giving a few details of the coding please someone help me to figure this out.
vb code ::
Code:
structure configtable
public pid as long
public configid as long
public wordno as long
public unit as string
public maxval as single
end structure
declearation of array in vb::
Code:
public para() as configtable
calling the dll function in vc++ ::
Code:
databaseinitialization(para,apppath)
the structure in dll::
Code:
typedef struct
{
int pid;
int configid;
int wordno;
LPVOID unit;
float maxval;
}PARAMETERS;
function where i got the error ::
Code:
databaseinitialization(LPSAFEARRAY FAR *prtPARAMDATA, LPSTR path)
{
PARAMETERS *paraTABLE;
paraTABLE=(PARAMETERS*) malloc (sizeof(PARAMETERS) * (*ptrPARAMDATA)->rgsabound->cElements); //the error line
}
i have also tried by giving like but den its givig some while compiling the dll:
Code:
paraTABLE=(PARAMETERS*) malloc (sizeof(PARAMETERS) * (*ptrPARAMDATA).rgsabound[0].cElements);
or
Code:
paraTABLE=(PARAMETERS*) malloc (sizeof(PARAMETERS) * ptrPARAMDATA->rgsabound->cElements);
but den its showing :
Code:
error C2227:left of '->rgsabound' must point to class/struct/union/generic type.
error C2227:left of '->cElements' must point to class/struct/union/generic type.
full code is not given but this line in the databaseinitialization is not executing.waiting for reply...
Re: accessing long pointer safearray structure in dll
i am extremely sorry that i didn't use code block last time.
i have tried the SafeArrayAllocData function but i don't know how to initialize the allocated memory to the PARATable, as its given :
Code:
paraTABLE=(PARAMETERS*) malloc (sizeof(PARAMETERS) * (*ptrPARAMDATA)->rgsabound->cElements);
and when i tried this code like its giving illigal use of expression :
Code:
paraTABLE=SafeArrayAllocDescriptor(PARAMETERS,ptrParamData)
Re: accessing long pointer safearray structure in dll
Why malloc?
use SafeArrayAllocDescriptor and SafeArrayAllocData instead.
And BTW, using Code tags without proper code indentation does not make any sense!
Re: accessing long pointer safearray structure in dll
please follow the full function of databaseinitialization. the previous developer write this code in vc++ 2005 , and while i debugging in 2008 its not executing.
Code:
void _stdcall DatabaseInitialization(LPSAFEARRAY FAR *ptrParamData, LPCSTR path)
{
PARAMETERS *ParaFiles ,
temp = {0};
unsigned int index = 0,stickyindex = 0;
int superfrmcnt = 0;
char *paraname ,
*unitname ,
*alias ,
//SpdFilePath[1024] ,
Dfdr[100] = {'\0'};
unsigned short int *refreshmemory ;
/******Global Parameters initialisations*************/
DfdrType = datalength;
/* if((fpmahesh = fopen( "MaheshDebug.txt", "w" )) == NULL )
{
MessageBox(NULL," Could not open MaheshDebug.txt file.","Error !",MB_OK );
exit(0);
}*/
itoa( DfdrType, Dfdr, 10 );
PARATable = (PARAMETERS *) malloc (sizeof(PARAMETERS) * (*ptrParamData)->rgsabound->cElements);//error line
Frame.subframe1 = (unsigned short int *) malloc (sizeof(short int ) * DfdrType);
Frame.subframe2 = (unsigned short int *) malloc (sizeof(short int ) * DfdrType);
Frame.subframe3 = (unsigned short int *) malloc (sizeof(short int ) * DfdrType);
Frame.subframe4 = (unsigned short int *) malloc (sizeof(short int ) * DfdrType);
prevFrame.subframe1 = (unsigned short int *) malloc (sizeof(short int ) * DfdrType);
prevFrame.subframe2 = (unsigned short int *) malloc (sizeof(short int ) * DfdrType);
prevFrame.subframe3 = (unsigned short int *) malloc (sizeof(short int ) * DfdrType);
prevFrame.subframe4 = (unsigned short int *) malloc (sizeof(short int ) * DfdrType);
tempFrame.subframe1 = (unsigned short int *) malloc (sizeof(short int ) * DfdrType);
tempFrame.subframe2 = (unsigned short int *) malloc (sizeof(short int ) * DfdrType);
tempFrame.subframe3 = (unsigned short int *) malloc (sizeof(short int ) * DfdrType);
tempFrame.subframe4 = (unsigned short int *) malloc (sizeof(short int ) * DfdrType);
tempFrame1.subframe1 = (unsigned short int *) malloc (sizeof(short int ) * DfdrType);
tempFrame1.subframe2 = (unsigned short int *) malloc (sizeof(short int ) * DfdrType);
tempFrame1.subframe3 = (unsigned short int *) malloc (sizeof(short int ) * DfdrType);
tempFrame1.subframe4 = (unsigned short int *) malloc (sizeof(short int ) * DfdrType);
refreshmemory = (unsigned short int *) malloc (sizeof(short int ) * DfdrType);
for (index = 0; (int)index < DfdrType ; index++ )
{
refreshmemory[index] = 0;
}
for (superfrmcnt = 0 ; superfrmcnt < 16 ; superfrmcnt++)
{
SFrame.frames[superfrmcnt].subframe1 = (unsigned short int *) malloc (sizeof(short int ) * DfdrType);
SFrame.frames[superfrmcnt].subframe2 = (unsigned short int *) malloc (sizeof(short int ) * DfdrType);
SFrame.frames[superfrmcnt].subframe3 = (unsigned short int *) malloc (sizeof(short int ) * DfdrType);
SFrame.frames[superfrmcnt].subframe4 = (unsigned short int *) malloc (sizeof(short int ) * DfdrType);
memcpy(SFrame.frames[superfrmcnt].subframe1,refreshmemory , sizeof(short int ) * DfdrType);
memcpy(SFrame.frames[superfrmcnt].subframe2,refreshmemory , sizeof(short int ) * DfdrType);
memcpy(SFrame.frames[superfrmcnt].subframe3,refreshmemory , sizeof(short int ) * DfdrType);
memcpy(SFrame.frames[superfrmcnt].subframe4,refreshmemory , sizeof(short int ) * DfdrType);
}
MemoryFreeFlag[0] = 1 ;
free(refreshmemory);//a function call
TotalParam = (*ptrParamData)->rgsabound->cElements;//error line
ClearParaTable( TotalParam );
ParaFiles=(PARAMETERS *)((*ptrParamData)->pvData);
for (index = 0;index <((*ptrParamData)->rgsabound->cElements); index++,ParaFiles++)//error line
{
unPackVBStr(ParaFiles->paraname , ¶name);
unPackVBStr(ParaFiles->aliasname , &alias);
unPackVBStr(ParaFiles->units , &unitname);
temp.pid = ParaFiles->pid ;
temp.configid = ParaFiles->configid ;
temp.wordno = ParaFiles->wordno ;
temp.maxval = ParaFiles->maxval ;
temp.units = unitname ;
PARATable[index] = temp;
// fprintf( fpmahesh, "%s\t%s\t%s\t%d\t%d\t%d\n ",
// temp.paraname, temp.aliasname, temp.units, temp.pid, temp.configid,
// temp.wordno );
}
// ** For copying sticky information ** //
ConfigID = temp.configid ;
//fclose( fpmahesh );
}
so where ever the line has been used its not showing error in dll but not executing in background.
what could be the other option that i can use instead of that line.
Re: accessing long pointer safearray structure in dll
Quote:
Originally Posted by
sumlal
Code:
databaseinitialization(LPSAFEARRAY FAR *prtPARAMDATA, LPSTR path)
{
PARAMETERS *paraTABLE;
paraTABLE=(PARAMETERS*) malloc (sizeof(PARAMETERS) * (*ptrPARAMDATA)->rgsabound->cElements); //the error line
}
i have also tried by giving like but den its givig some while compiling the dll:
Code:
paraTABLE=(PARAMETERS*) malloc (sizeof(PARAMETERS) * (*ptrPARAMDATA).rgsabound[0].cElements);
or
Code:
paraTABLE=(PARAMETERS*) malloc (sizeof(PARAMETERS) * ptrPARAMDATA->rgsabound->cElements);
but den its showing :
Code:
error C2227:left of '->rgsabound' must point to class/struct/union/generic type.
error C2227:left of '->cElements' must point to class/struct/union/generic type.
full code is not given but this line in the databaseinitialization is not executing.waiting for reply...
The error is, I guess, because the ptrPARAMDATA and prtPARAMDATA are two different identificators.
Re: accessing long pointer safearray structure in dll
As victor said in his post #4, please use proper indentation when posting code so that it's readable.
This is c rather than c++ code. When using malloc you need to check the assigned variable for NULL to see if memory has actually been assigned or not.
Before the call the malloc is made, what is the value of (*ptrParamData)->rgsabound->cElements ? If this is not a sensible value then malloc will probably fail but you aren't checking for that as I mentioned above.
Have you tried
Code:
paraTABLE=(PARAMETERS*) malloc (sizeof(PARAMETERS) * (*ptrPARAMDATA)->rgsabound[0].cElements);
Re: accessing long pointer safearray structure in dll
Quote:
Originally Posted by
sumlal
so where ever the line has been used its not showing error in dll but not executing in background.
First of all, you have to explain your solution architecture clearly and unambiguously. I have to admit that I totally lost in your frontends, backends, showing errors and executing in backgrounds.
If I were you, I would make an isolated sample replicating your problem and demonstrating what calls what, and posted it here on the forum. The sample must not access any real database, you just fill the array with some pre-defined data and see how it comes to your c++ dll.
If I understand you correctly, the sample is to consist of two dlls, vb and c++, and some launcher app for driving vb dll.
Re: accessing long pointer safearray structure in dll
Quote:
First of all, you have to explain your solution architecture clearly and unambiguously. I have to admit that I totally lost in your frontends, backends, showing errors and executing in backgrounds.
If I were you, I would make an isolated sample replicating your problem and demonstrating what calls what, and posted it here on the forum. The sample must not access any real database, you just fill the array with some pre-defined data and see how it comes to your c++ dll.
If I understand you correctly, the sample is to consist of two dlls, vb and c++, and some launcher app for driving vb dll.
may be sir i can,t able to explain the problem properly in this code, i have just joined as a trainee in an organization and don't have that much experience to dealing with such type of error, and also because i am aslo not getting y this error is comming..the application is consist of several dll in the back-end (mainly in vc++) and the luncher application is in vb, and yes there are some vb dll also but no problem with them.
when i releasing the dll its working smoothly with the above code (posted at #1) but with application its not working properly. so,to track the error i included a massegebox after every statement in that dll and thus i got to know which line is having he problem.
what ever i have studied this problem i am still having some confusion in the concept,
If u see in the above function they have declear a structure array in vb
Code:
structure configtable
public pid as long
public configid as long
public wordno as long
public unit as string
public maxval as single
end structure
public para() as configtable
and they passed the array to the dll function where the "datainitialization()" is present in a dll and this function is having no connectivity with others dll
Code:
databaseinitialization(para,apppath)
at the next step in dll they accessing the parameter as LPSAFEARRAY
Code:
void _stdcall databaseinitialization(LPSAFEARRAY FAR *prtPARAMDATA, LPSTR path)
they are using that LPSAFEARRAY to allocate the memory as
Code:
PARAMETERS *paraTABLE;
paraTABLE=(PARAMETERS*) malloc (sizeof(PARAMETERS) * (*ptrPARAMDATA)->rgsabound->cElements); //the error line
so the question is they are not assinging any value to the "cElements" before this statement but they are using this variable to allocate memory , is this possible to allocate memory like this ? and if yes then how ? i am not that much familiar with SAFEARRAY concept so i am having confusion with that.
and then if u can see they are allocating memory and initialize that memory to another structure variable "PARAMETERS" which is defined in the same dll as
Code:
typedef struct
{
int pid;
int configid;
int wordno;
LPVOID unit;
float maxval;
}PARAMETERS;
waiting for reply.....
Re: accessing long pointer safearray structure in dll
sorry sir, that was my mistake only. it was a typing mistake while i was writing in this forum.
Re: accessing long pointer safearray structure in dll
Quote:
Originally Posted by
sumlal
sorry sir, that was my mistake only. it was a typing mistake while i was writing in this forum.
Yes, you did a lot of mistakes. One of them was what I wrote you in the post#7.
Another one is you got rid of proper code indentation.
The next - you got rid of proper text punctuation and spell checking.
:eek:
Re: accessing long pointer safearray structure in dll
Quote:
Originally Posted by
VictorN
Yes, you did a lot of mistakes. One of them was what I wrote you in the post#7.
Another one is you got rid of proper code indentation.
The next - you got rid of proper text punctuation and spell checking.
:eek:
Thank u for correcting me with all this things. but still i couldn't found any way to resolve the problem. If u can understand the problem can u help me out ..!! u can follow the post#6 and post#10.
Re: accessing long pointer safearray structure in dll
Have you already fixed the "mistake" with ptrPARAMDATA and prtPARAMDATA variables I mentioned in the post#7?
Re: accessing long pointer safearray structure in dll
Quote:
Originally Posted by
sumlal
waiting for reply.....
You may be, but you're not going to have any certain answer until you provide us with a sufficient information I asked you about. Why is it so important to provide a concise and compilable project?
First of all, by composing one you eliminate any unnecessary "informational noise" and let us focus specifically on your problem.
Second, having a compilable and runnable solution people here can see all the tiny details you may consider unimportant while those are important in fact. E.g., you mention VB. What version of VB? Is it VB6.0 or VB.NET? Or other thing, you show us how the function is declared in C++ dll but never do that for VB side. I'm sure there might be other points you failed to report.
So the bottom line is: you are to provide a small compilable project or projects that together replicate your issue.
PS. There may be Third as well. The issue have good chances to be solved right when you compose a small project replicating it, just because you "peel the peach." Trust me, I know what I'm talking about as I do this for decades.