Click here to Skip to main content
15,925,602 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Excel Pin
kjessee26-Apr-03 11:11
kjessee26-Apr-03 11:11 
GeneralRe: Excel Pin
Heiko200326-Apr-03 11:22
sussHeiko200326-Apr-03 11:22 
GeneralRe: Excel Pin
kjessee26-Apr-03 12:17
kjessee26-Apr-03 12:17 
GeneralGreat Genius DavidCrow, please help me again Pin
Heiko200326-Apr-03 12:36
sussHeiko200326-Apr-03 12:36 
GeneralRe: Great Genius DavidCrow, please help me again Pin
kjessee26-Apr-03 17:29
kjessee26-Apr-03 17:29 
GeneralRe: Great Genius DavidCrow, please help me again Pin
Heiko200327-Apr-03 1:30
sussHeiko200327-Apr-03 1:30 
GeneralProblem solved Pin
Heiko200327-Apr-03 4:02
sussHeiko200327-Apr-03 4:02 
General2-D SafeArray Pin
tomercagan26-Apr-03 10:11
tomercagan26-Apr-03 10:11 
I am trying to write a DLL to be called from VB. Thus I had to use SAFEARRAY.
I have a problem that when I am accessing all the elements in the array I can change their values but when I try to access a specific element it seems not to accept the new value I try to assign.

For example, I have these functions:

void Set2DSafeArrayPtr(SAFEARRAY * psaiInOut, long val)
{
long ai[2];
int x,y;
LRESULT hres;
int xMin = psaiInOut->rgsabound[0].lLbound;
int xMax = xMin + (int)psaiInOut->rgsabound[0].cElements - 1;
int yMin = psaiInOut->rgsabound[1].lLbound;
int yMax = yMin + (int)psaiInOut->rgsabound[1].cElements - 1;
// Set up dimension array and pointer to receive value.
long * piInOut;
if (hres = SafeArrayLock(psaiInOut)) throw hres;
for (x = xMin; x <= xMax; x++) {
ai[0] = x;
for (y = yMin; y <= yMax; y++) {
ai[1] = y;
hres = SafeArrayPtrOfIndex(psaiInOut, ai, (void **)&piInOut);
if (hres) throw hres;
// Equivalent to: aiInOut(x, y) = aiInOut(x, y) + 1.
(*piInOut) = val;
}
}
if (hres = SafeArrayUnlock(psaiInOut)) throw hres;
}

void SetElementPtr(SAFEARRAY * psaiInOut, int x, int y, long val)
{
LRESULT hres;
long * piInOut;
long ai[2];
if (hres = SafeArrayLock(psaiInOut)) throw hres;

ai[0] = x;
ai[1] = y;
hres = SafeArrayPtrOfIndex(psaiInOut, ai, (void **)&piInOut);
if (hres) throw hres;

(*piInOut) = val;

if (hres = SafeArrayUnlock(psaiInOut)) throw hres;
}

my program

void main{
...
SAFEARRAYBOUND bDim[2];
bDim[0].lLbound = 0;
bDim[0].cElements = 6;
bDim[1].lLbound = 0;
bDim[1].cElements = 6;

psaiNew = SafeArrayCreate(VT_I4, 2, bDim);
if(psaiNew == NULL){
cout << "Unable to initialize array. Not enough memory" << endl;
return;
}

hres = SafeArrayLock(psaiNew);


Set2DSafeArrayPtr(psaiNew, 15);
SetElementPtr(psaiNew, 1,2,30);

hres = SafeArrayUnlock(psaiNew);
...
}

The Set2DSafeArrayPtr seems to work fine but the SetElementPtr doesn't seem to work.

Any idea why? What am I doing wrong?
I'd also like to know of a good place I can find references/examples (other then MSDN)...
QuestionHow to UPDATE_COMMAND_UI in Dialog App? Pin
work_to_live26-Apr-03 7:25
work_to_live26-Apr-03 7:25 
AnswerRe: How to UPDATE_COMMAND_UI in Dialog App? Pin
valikac26-Apr-03 8:23
valikac26-Apr-03 8:23 
GeneralRe: How to UPDATE_COMMAND_UI in Dialog App? Pin
work_to_live26-Apr-03 8:51
work_to_live26-Apr-03 8:51 
GeneralRe: How to UPDATE_COMMAND_UI in Dialog App? Pin
work_to_live26-Apr-03 9:17
work_to_live26-Apr-03 9:17 
GeneralRe: How to UPDATE_COMMAND_UI in Dialog App? Pin
work_to_live26-Apr-03 10:17
work_to_live26-Apr-03 10:17 
AnswerRe: How to UPDATE_COMMAND_UI in Dialog App? Pin
Michael Dunn26-Apr-03 18:42
sitebuilderMichael Dunn26-Apr-03 18:42 
GeneralRe: How to UPDATE_COMMAND_UI in Dialog App? Pin
work_to_live26-Apr-03 23:20
work_to_live26-Apr-03 23:20 
AnswerRe: How to UPDATE_COMMAND_UI in Dialog App? Pin
Baris Kurtlutepe26-Apr-03 23:22
Baris Kurtlutepe26-Apr-03 23:22 
GeneralRe: How to UPDATE_COMMAND_UI in Dialog App? Pin
work_to_live27-Apr-03 11:07
work_to_live27-Apr-03 11:07 
GeneralWin 9x SetWindow Rgn Problem Pin
nemo26-Apr-03 6:36
nemo26-Apr-03 6:36 
Generaltelephone-conversation Recorder Pin
ZarrinPour26-Apr-03 5:37
ZarrinPour26-Apr-03 5:37 
GeneralGDI question Pin
pankajdaga26-Apr-03 5:32
pankajdaga26-Apr-03 5:32 
GeneralSwitch static Splitter Windows Pin
schoni26-Apr-03 4:17
schoni26-Apr-03 4:17 
GeneralStyle question - low priority. Pin
73Zeppelin26-Apr-03 4:14
73Zeppelin26-Apr-03 4:14 
GeneralRe: Style question - low priority. Pin
Ravi Bhavnani26-Apr-03 4:44
professionalRavi Bhavnani26-Apr-03 4:44 
GeneralRe: Style question - low priority. Pin
Hans Dietrich27-Apr-03 0:00
mentorHans Dietrich27-Apr-03 0:00 
GeneralDisplaying Jpg in Listview Pin
Mortis26-Apr-03 3:10
Mortis26-Apr-03 3:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.