Click here to Skip to main content
15,921,660 members
Home / Discussions / COM
   

COM

 
GeneralCOM Voodoo Pin
vlvl28-Apr-03 21:06
vlvl28-Apr-03 21:06 
GeneralRe: COM Voodoo Pin
safee ullah29-Apr-03 0:56
safee ullah29-Apr-03 0:56 
GeneralRe: COM Voodoo Pin
Stephane Rodriguez.7-May-03 20:49
Stephane Rodriguez.7-May-03 20:49 
QuestionADO events biased to COM memory model? Pin
Chopper28-Apr-03 9:31
Chopper28-Apr-03 9:31 
GeneralCOM interop to Outlook -- BeforeFolderSwitch Pin
rkiesler27-Apr-03 3:57
rkiesler27-Apr-03 3:57 
GeneralRe: COM interop to Outlook -- BeforeFolderSwitch Pin
Stephane Rodriguez.7-May-03 20:52
Stephane Rodriguez.7-May-03 20:52 
GeneralRe: COM interop to Outlook -- BeforeFolderSwitch Pin
rkiesler9-May-03 5:32
rkiesler9-May-03 5:32 
General2-D SafeArray Pin
tomercagan26-Apr-03 10:10
tomercagan26-Apr-03 10:10 
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)...
GeneralRe: 2-D SafeArray Pin
Hans Ruck30-Apr-03 1:13
Hans Ruck30-Apr-03 1:13 
GeneralOLE DB problem in VC++ COM when used in ASP Pin
Mahesh Perumal26-Apr-03 2:20
Mahesh Perumal26-Apr-03 2:20 
Generalne One Heard of CAutomationObject Pin
safee ullah23-Apr-03 21:40
safee ullah23-Apr-03 21:40 
QuestionWhat cause such link errors? Pin
ray_li23-Apr-03 10:41
ray_li23-Apr-03 10:41 
AnswerRe: What cause such link errors? Pin
Anonymous3-May-03 2:07
Anonymous3-May-03 2:07 
General_variant_t Pin
Anthony_Yio21-Apr-03 19:42
Anthony_Yio21-Apr-03 19:42 
GeneralRe: _variant_t Pin
Hans Ruck23-Apr-03 4:46
Hans Ruck23-Apr-03 4:46 
GeneralRe: _variant_t Pin
Renjith Ramachandran15-May-03 7:07
Renjith Ramachandran15-May-03 7:07 
QuestionHow to catch new enent of OFFICE WORD Pin
yanshiqi21-Apr-03 16:10
yanshiqi21-Apr-03 16:10 
AnswerRe: How to catch new enent of OFFICE WORD Pin
Anonymous22-Apr-03 0:31
Anonymous22-Apr-03 0:31 
GeneralThreads in COM Pin
rattagarn18-Apr-03 1:16
rattagarn18-Apr-03 1:16 
GeneralRe: Threads in COM Pin
Imran_Farooqui18-Apr-03 1:23
sussImran_Farooqui18-Apr-03 1:23 
GeneralCOM server location on CLSID Pin
thowra17-Apr-03 23:30
thowra17-Apr-03 23:30 
GeneralRe: COM server location on CLSID Pin
Abebe28-Apr-03 23:08
Abebe28-Apr-03 23:08 
GeneralRe: COM server location on CLSID Pin
thowra29-Apr-03 3:13
thowra29-Apr-03 3:13 
GeneralApplication is still running or a crash occured Pin
ovidiu_pon17-Apr-03 22:07
ovidiu_pon17-Apr-03 22:07 
GeneralOverloading an Interface Method in VC++ COM Pin
Vidya Ramani16-Apr-03 23:50
Vidya Ramani16-Apr-03 23:50 

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.