|
see i have created the com dll for shell context menu ..
if (DragQueryFile((HDROP)medium.lpszFileName, i, path, MAX_PATH))
{
g_szSelectedFiles.SetAt(i, path);
szFileName = g_szSelectedFiles[i];
}
from here i am getting the path (szFileName )i want in exe code so that i can proceed this my doubt ..
the variable is decalred as static in header file of the dll .i link the library of dll .the scope is not remaining .....
Best Regards
Sarfaraz
|
|
|
|
|
What do you mean by "i want in exe code"; I am afraid that makes little sense.
Use the best guess
|
|
|
|
|
the path(Szfilename)is useed in dll .Now this szfilename path i want use in the application code .
i explain how i tried i linked the dll lib to an application code and then i included the header file of the dll in an application code so that i can use the path(szfilename).
this szfilename is declared in static so its scope remain in application code also ..
|
|
|
|
|
Then you either need to export it from the dll or provide a function that will return it to the calling application.
Use the best guess
|
|
|
|
|
Hi,
I have the following code sequences whose pourpose is to display a .txt file in a Excel Spreadsheet, however the .txt file is not being loaded after I execute workbooks.opentext
a workbook is loaded but there are no sheets displayed let alone text
I get good return codes from IDispatch->invoke and good return codes in excpInfo
I have changed the file name to a bogous name and the same thing happens
app.CreateDispatch("Excel.Application"); Workbooks objBooks(app.Workbooks());
Workbooks objBooks = app.GetWorkbooks();
COleVariant FilenameOpen(File),
FilenameSave(XlsFile),
Origin((short)2), StartRow((short)1),
DataType((short)1), TextQualifier((short)1), ConsecutiveDelimiter((long)FALSE, VT_BOOL),
Tab((long)FALSE, VT_BOOL),
Semicolon((long)TRUE, VT_BOOL),
Comma((long)FALSE, VT_BOOL),
Space((long)FALSE, VT_BOOL),
Other((long)FALSE, VT_BOOL),
Otherchar((long)FALSE,VT_BOOL),
Fieldinfo((long) FALSE, VT_BOOL),
TextVisualLayout((long)FALSE, VT_BOOL),
DecimalSeperator((long) FALSE, VT_BOOL),
ThousandSepartor((long) FALSE, VT_BOOL),
TrailingMinusNumbers((long) FALSE, VT_BOOL),
Local((long) FALSE, VT_BOOL),
Fileformat((short)33), Save((long)FALSE, VT_BOOL);
COleSafeArray saRet;
DWORD numElements[2];
numElements[0] = 2;
numElements[1] = 2;
saRet.Create(VT_I4,2,numElements);
long index[2];
long val;
index[0]=0;
index[1]=0;
val = 1;
saRet.PutElement(index,&val);
index[0] = 1;
index[1] = 0;
val = 2;
index[0] = 1;
index[1] = 1;
val = 9;
objBooks.OpenText((LPCTSTR)"C:\\Program Files\\Microsoft VIsual Studio\\MyProjects\\I46023\\I46023.txt", Origin, COleVariant((long)1),COleVariant((long)1),
1,
ConsecutiveDelimiter, Tab, Semicolon,
Comma,Space,Other,Otherchar,saRet,TextVisualLayout,
DecimalSeperator,ThousandSepartor,TrailingMinusNumbers,
Local);
app.SetVisible(true);
app.SetUserControl(TRUE);
|
|
|
|
|
Why are you using the (LPCTSTR) cast on your file path? Do you fully understand what a cast does?
Use the best guess
|
|
|
|
|
Richard
This is the function prototype in excel.cpp
oid Workbooks::OpenText(LPCTSTR Filename, const VARIANT& Origin, const VARIANT& StartRow, const VARIANT& DataType, long TextQualifier, const VARIANT& ConsecutiveDelimiter, const VARIANT& Tab, const VARIANT& Semicolon, const VARIANT& Comma,
const VARIANT& Space, const VARIANT& Other, const VARIANT& OtherChar, const VARIANT& FieldInfo, const VARIANT& TextVisualLayout, const VARIANT& DecimalSeparator, const VARIANT& ThousandsSeparator, const VARIANT& TrailingMinusNumbers,
const VARIANT& Local)
Filename is Of type LPCTSTR
Thanks
|
|
|
|
|
ForNow wrote: Filename is Of type LPCTSTR Then you should provide a LPCTSTR in your call, rather than providing a LPCSTR , and then telling the compiler to ignore the fact that the string may not be in the correct format. Lookup the use of the TEXT() macro and make sure your strings are generated correctly, and read the documentation on the correct use of casts.
Use the best guess
|
|
|
|
|
The Text macro interperts the string if ansi is defined according to the current codepage
I think the string I am passing is being interpetted correctly
looking at the varaint type of the file it was being interpetted as a VT_BSTR
and had the correct value
case VT_BSTR:
{
LPCOLESTR lpsz = va_arg(argList, LPOLESTR);
pArg->bstrVal = ::SysAllocString(lpsz);
if (lpsz != NULL && pArg->bstrVal == NULL)
AfxThrowMemoryException();
|
|
|
|
|
ForNow wrote: I think the string I am passing is being interpetted correctly By luck, not judgement; if your project is built in UNICODE mode then it will be wrong. You should not use a cast unless you understand the consequences. Instead, use the TEXT() macro to ensure that your character string is generated in the appropriate character set to match the build. Your cast in the foregoing code is telling the compiler to ignore the fact that the string may be in the wrong character set.
Use the best guess
|
|
|
|
|
I am getting the above error from WorkBooks::OpenText
As all of the 18 paramters are optional
besides the first
I VT_NULL'ed all of them besdies the file name and still got the error
Since there is a lot of security where I work
I used the program name as the text file and still got the above errors
Any Help would be appreciated
|
|
|
|
|
You should make an effort to research error codes first: see here[^] for a number of possibilities.
|
|
|
|
|
Hi,
I am get an assert error when calling WorkBooks::OpenText
I traced it down the code to dispatch->invoke and the return code from that
was 0x80020008 DISP_E_BADVARTYPE One of the arguments in rgvarg is not a valid variant type.
I had a VARIANT for all my arguments besides the 5th which is a long
My question is then the following almost all the paramters are optional
besdides the first which is the filename
I assumed optional was a NULL so.
I coded the following for NULL
VARIANT varfalse.
varfalse.intVal = 0;
varfalse.vt = VT_INT;
is this correct ?
thanks
.
|
|
|
|
|
ForNow wrote: is this correct ?
no ... you should use
varfalse.vt = VT_EMPTY
or
varfalse.vt = VT_NULL
|
|
|
|
|
Hi,
I getting the above return code the following is my code sequence
CLSID clsid;
HRESULT hr = CLSIDFromProgID(L"Excel.Application",&clsid)
IDispatch *pWApp;
hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER,
IID_IDispatch, (void **)&pWApp);
LPOLESTR ptName = (LPOLESTR) _T("OpenText");
DISPID dispID;
hr = pWApp->GetIDsOfNames(IID_NULL, &ptName, 1 , LOCALE_USER_DEFAULT,&dispID);
I am using VIsual C++ 6.0 excel 2003
Thanks
|
|
|
|
|
|
For CoInitialize I am getting a 0x00000001 S_FALSE (already initliazed)
For CLSIDFromProgID I am getting a 0x00000000 S_OK
For CoCreateInstance I am getting a 0x00000000 S_OK
For GetIDsOfNames I am getting a 0X80020006 DISP_E_UNKNOWNNAME
Thanks
|
|
|
|
|
I have tried this code with a variety of names (supposedly in Excel) but get the same response each time. The MSDN documentation is not very helpful so I'm not sure where to go from here. However, once again I would ask, what problem are you actually trying to solve?
|
|
|
|
|
I just tried again with the name "worksheets" and it worked. So, the code is correct, but the name you are using is not.
|
|
|
|
|
Very good you are right on the key is the first paramter
_In_ LPCOLESTR lpszProgID,
The Class id name, Excel is divded into for objects Application, Workbook, Worksheet, and I think Range
In Visual C++ 6.0 there is a OLE/COM viewer which might kind a hint of the names
What I am trying to do,
My boss gave me an assignment to automate the pasting of .txt file onto a Excel Worksheet
I wanted this app to be MFC based as I might need to employ windows services
Hence the main thread CWinApp and associated mainwindow
Thanks again for your help
|
|
|
|
|
|
|
I am going to go with the method you pointed out had using AS i GET BY THE
DISP_E_UNKNOWN
Maybe the way excel was installed it ddn't make entries
for HKCR\Typlib for the excel methods properties
Thanks
|
|
|
|
|
|
|