|
i wanna contruct a safearray,which is made up of VARIANT type element,which vt = VT_BSTR;i use SafeArrayCreate to create the safearray,then use SafeArrayPutElement to add element into array one by one,it's ok,and (this is just my test code) if i use SafeArrayGetElement to get the element that just now put into the array,on the neck of the SafeArrayPutElement at the same cycle statement,it's all right.
but if i write the SafeArrayGetElement out of the same cycle,the program
crashed.why?it's so strange.
my codes are as follows:
VARIANT *pvarCis = new VARIANT[nCount];
for(int i = 0;i < nCount;i++)
{
CComBSTR bstrCi(arCi.GetAt(i));
(pvarCis + i)->vt = VT_BSTR;
(pvarCis + i)->bstrVal = bstrCi.Copy();
}
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = nCount;
SAFEARRAY * psa = NULL;
psa = SafeArrayCreate(VT_VARIANT, 1, rgsabound);
if(psa)
{
psa->cbElements = nCount;
VARIANT *pvarCellInfo = new VARIANT[nCount];
HRESULT hresult;
for(long lIndex = 0; lIndex < nCount; lIndex++)
{
hresult = SafeArrayPutElement(psa,&lIndex,&pvarCis[lIndex]);
if(FAILED(hresult))
return;
hresult = SafeArrayGetElement(psa,&lIndex,&pvarCellInfo[lIndex]);
if(FAILED(hresult))
return;
}
for(lIndex = 0;lIndex < nCount; lIndex++)
{
hresult = SafeArrayGetElement(psa,&lIndex,&pvarCellInfo[lIndex]);
if(FAILED(hresult))
return;
}
... ...
}
|
|
|
|
|
cbElements must equal the size of an element of the array. Try with:
psa->cbElements = sizeof(<code>VARIANT</code>);
"no xe tuto oro quel che luse"
rechi+
|
|
|
|
|
Hello XPointer,
I tried your sample source code and discovered that the error lies around the following lines :
if(psa)
{
//psa->fFeatures = FADF_VARIANT;
psa->cbElements = nCount; // <-- should not set cbElements.
...
...
...
The "cbElements" field is already set when you called the SafeArrayCreate() function earlier :
psa = SafeArrayCreate(VT_VARIANT, 1, rgsabound);
Furthermore, this field indicates the size of each element of the array and since the element type has been declared to be VT_VARIANT, "cbElements" should be sizeof(VARIANT), i.e. 16 bytes, and should not be "nCount".
However the fields of the SAFEARRAY struct (including fFeatures) should all be transparent to developers and should only be accessed via APIs and not modified or accessed individually.
I suggest commenting out the line :
psa->cbElements = nCount;
Your code should work fine thereafter.
Best Regards,
Bio.
|
|
|
|
|
Hope this helps.. this creates a variant made of a safe array of variant which themselves are strings!
Just ignore the last 3 lines of code!
void CVariantTools::ToVariant(VARIANT & var,const CStringArray & arrColumns)
{
// Create the array
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = arrColumns.GetSize();
SAFEARRAY FAR* pArrayCol = SafeArrayCreate(VT_VARIANT, 1, rgsabound);
// Fill it with the column property
for ( int nCol=0; nCol < arrColumns.GetSize(); nCol++)
{
long rgIndice=nCol;
COleVariant oleValue(arrColumns.GetAt(nCol),VT_BSTR);
SafeArrayPutElement(pArrayCol,&rgIndice,&oleValue);
}
// Prepare the variants
VariantClear(&var);
var.vt=VT_ARRAY|VT_VARIANT;
var.parray = pArrayCol;
}
|
|
|
|
|
thanks Bogdan Rechi, Lim Bio Liong and BadJerry ,
now i complete my src according to your advice,thanks.
btw,i just considerred 'the Size of an element' to 'the number of elements' by mistake,so the error occurred certainly.it's my carelessness
thanks a lot!!!
|
|
|
|
|
Hi guys,
I've got a ASP .Net application which uses a COM object. I've turned on impersonation and assigned a valid windows user. The system.security.principle.windowsidentity.getcurrent.name property correctly returns the logon user.
However, the COM is still running under the ASPNET identity. I know this because I've added a function in the COM object to return the current user(win32 API).
How do I overcome this problem? The COM object needs to run under a non ASPNET account in order for it to access another server.
Thanks.
|
|
|
|
|
I am attempting to create a class using C# or C++ that can be called from Visual Basic for Applications in Excel. I have tried several examples from CodeProject, Microsoft, and others, but whether I use the regasm utility or check the C# compiler option "Register for COM Interop", I get a message to the effect that there are no types that can be registered for COM Interop. I must be missing something obvious... any suggestions?
|
|
|
|
|
RegAsm registers any types that are public, do not have the ComVisible(false) attribute applied, and have a default constructor (one which takes no arguments). Also, any types used as parameters must be Automation-compatible. Any classes that are used as parameters must also conform to these requirements.
|
|
|
|
|
Thanks for the info. The Microsoft article does not mention the ComVisible attribute, which is obvious now that you've pointed it out. However, now I have another problem, which is that, when I select the add-in in the Automation Servers dialog box (Tools/Add-Ins/Automation Servers) in Excel, I get a message to the effect that it can't find mscoree.dll. That file's directory (C:\WINDOWS\system32) is included in the PATH environment variable, so it should be findable. Even copying mscoree.dll into the Excel application, add-in, or library directories does not help. Any suggestions?
|
|
|
|
|
Thanks for the info. The Microsoft article does not mention the ComVisible attribute, which is obvious now that you've pointed it out. However, now I have another problem, which is that, when I select the add-in in the Automation Servers dialog box (Tools/Add-Ins/Automation Servers) in Excel, I get a message to the effect that it can't find mscoree.dll. That file's directory (C:\WINDOWS\system32) is included in the PATH environment variable, so it should be findable. Even copying mscoree.dll into the Excel application, add-in, or library directories does not help. Any suggestions?
|
|
|
|
|
Hi,
I am building a word document using C# and Word .NET Programmability however I have a question that I cannot find the answer for.
I have designed the Word template with embedded bookmarks.
When I build the document I dynamically place text at each book mark position.
The base document also has some other fixed text in it.
However in the completed document the original text is always moved.
EG:
Original document
MyText More MyText
Completed document
MyText [C# Added Text] More MyText
It seems that the original text is moved along a number of tab spaces.
Is there anyway to prevent this so that the layout of the completed document is the
same as the original (the only difference is the added text)?
I know that the spaces I left in the template are sufficient for the text I want to add.
Any help/advice greatly appreciated.
Regards Andrew
|
|
|
|
|
Move your range to Range.Characters.Last and then try inserting text through c#. this will insert the text at EOD
Hope this helps
--------------
Pavan Kulkarni
|
|
|
|
|
Hello,
I have Visual C++ program that implements Graphical User Interface (GUI). This program uses CWinApp, CFormView, CFrameWnd, and CDocument.
Now I need to package this C++ application to work as COM DLL (or ActiveX).
This program must be used as popup window from another program written in Java.
Is it possible to convert Visual C++ program with GUI into COM DLL or ActiveX ?
|
|
|
|
|
Hi all,
I have a problem in identifying which click was pressed.
Iam building two groups A and B.Each group contains one textbox and add button(all are builded dynamically).If i click on add button it should add textboxes to respective group.For add button click iam adding attributes and incrementing value from javascript using a hidden variable.
btnAddRange.Attributes.Add("onclick","javascript:submitVIN('"+GroupId+"')") this is code for click on a button.How can we identify click is performed on respective group.
Any help is greatly appreciated.
Thanks,
Vijaya
vijaya
|
|
|
|
|
which application it is??(MFC APP)
|
|
|
|
|
Hi,
I have a dll file that has implemented in framework 2.0 (VS 2005), but it has not used any advanced libraries. It is a vs2003 project, but have opened in VS2005. I have lost the code, what i have only the dll and now i want to add it to a vs2003 project. But it does not allow me to add it as a referrence. The problem is, it is a 2005 file.
Can I convert the dll to framework 1.1???????
Thanks in advanced!
jayasshc
|
|
|
|
|
Hi all.
I am having a problem passing a SAFEARRAY of IDispatch pointers to an outproc server. The problem occures when the outproc server goes to access one of IDispatch Interfaces method. The code work fine in inproc server.
Thanks in advance.
satindar
|
|
|
|
|
Hello satindar_kumar,
Make sure that the type library of the original interface (which contains the method that takes the SAFEARRAY of IDispatch pointers as parameter) is registered properly. Also make sure that the type library(ies) of each of the interfaces contained inside the SAFEARRAY is/are registered properly.
The type libraries must be registered because marshaling will definitely be required if the server is outproc.
In the case of inproc server, marshaling may not be needed hence the code worked fine. However, take note that if the interface is accessed cross-apartment, then marshaling will be required and hence the type libraries will need to be properly registered.
Hope the above helps,
Bio.
|
|
|
|
|
Good day. I am busy try to build an install for my project using WixEditor. I am struggling as this project has Dlls and one of these Dlls runs a CategoryInstaller that load Counter to a machine during the install. Can anyone point me to the right direction as to how to use Wix and how to reference DLLs and all, using Wix
Thanks
Kulile --- RSA
|
|
|
|
|
Did you mean a PerformanceCounterInstaller member?
WiX is the Windows Installer XML toolset. It doesn't really know much about what Visual Studio's deployment projects are up to. The .NET XxxInstaller classes seem to be intended for use with Visual Studio's deployment projects, which include Custom Action DLLs in your package which load the framework and run the Installer class.
WiX includes a performance counter custom action[^]. To use this, you need to create a .h and .ini file containing the descriptions of your performance counters. However, I don't know how to get this out of the Framework.
You may get a better answer by asking on the wix-users[^] mailing list.
|
|
|
|
|
Hello, everyone.
Please see below the description of a problem I met:
1. The Goal
The goal is to open the MS Excel document in read-only mode (so that it will be accessible for users while it is in use by my application). The access to the document is performed using COM. The application is written in VC++ using ATL.
2. The problem.
The "Open" method of the Workbooks object receives 13 parameters: the first is required (the path to the document), the others are optional.
The third parameter is ReadOnly, i.e. the parameter which controls the mode (r- or rw).
Therefore, to open a document in rw mode I have to pass only one (first parameter) - and it works fine.
But if I decide to open it in r- mode I will need to pass all 13 parameters. And here is there the problem occurs: I can not get IDispatch for a document if I pass all parameters.
Ok, I'm a not a lazy guy . I tried following options:
1) all parameters except 1-st and 3-d were passed as VT_EMPTY
2) all parameters except 1-st and 3-d were passed as VT_NULL
3) all parameters except 1-st and 3-d were initialized with the neutral values (which I got from the MS Excel Help for VB programming).
In all cases the result was the same: I got VT_EMPTY in the resulting VARIANT (please note, that the only thing I had to do, in order to open a document - change the number of parameters from 13 to 1).
Frankly speaking, I'm in the dark...
Have you ever met such problem? Could you please advice, where I'm wrong (since there is no doubt that I am)?
Your help is much appreciated. Thank you very much in advance.
|
|
|
|
|
I'm not sure which interface or method you're using, but since it looks like you're using a dispinterface I'd suspect the ReadOnly argument to be a VARIANT.
Try setting the ReadOnly argument to boolean type (VT_BOOL) and assign it VARIANT_TRUE or VARIANT_FALSE depending on you needs.
If it doesn't work, post again and describe what interface you're using and what methods you're calling.
Hope this helps
--
Roger
It's supposed to be hard, otherwise anybody could do it!
Regarding CodeProject: "resistance is pointless; you will be assimilated"
|
|
|
|
|
Hi,
Can anybody help me to get Icon details like its name, target path, working directory whenever it is double-clicked to run the application. This is be using Windows API or in C#.
I have already used IShellLink Interface but its been hard-coded for icon name. Suppose the user changes desktop icon name then also coding should be able to change its working directory. This can be done if I can check the existence of the icon.
Regards.
|
|
|
|
|
Help me on Creating a Crystal report using a predifined template with vc++ 6.0
I have tried so many times to create a new report using crystal report 11 by incorporating a template with vc++. I didnot find any article or sample code which is written in c++. But after some effort I got to know that there is a function called put_ReportTemplate() which is used for this task. I already know how to create a new report without using a template.
If anybody can help me by supplying a vc++ code on creating a Crystal report using a predifined template, it will be greatly appreciated.
Thanks.
SabseJugs
|
|
|
|
|
Hi
In com what does stub and proxy indicate?
I think proxy indicate interface file
class IComponent :public IUnknown; right?
What does stub mean?
Thanks.
|
|
|
|