|
I can spot two problems with your code.
1. You cannot read a drive. You have to read a file. What exactly is it you want to do? If you want to read raw data from the hard drive sector by sector, you'll need a different API.
2. You cannot close the handle before accessing the file mapping. Read what you have to, and close the file once you're done.
sarfaraznawaz wrote: one more thing i want to ask that is there any way to hide the folder or file.....
I saw you started a new thread for this, which is good. Keep that discussion there, and you will more likely attract others who might know.
|
|
|
|
|
thanks ...........
ya i want to read raw data from the hard drive sector by sector which is are the API are there
|
|
|
|
|
I found the following article on MSDN[^]. It's for reading sectors off a CD_ROM drive. Maybe it's possible for hard drives as well.
If not, I suggest you start a new thread with this more specific requirement. (Reading sector by sector.)
|
|
|
|
|
How to use Microsoft Scripting Runtime in WIN32 C++
want to use this function GetDrive("C:\").IsReady
Some Day I Will Prove MySelf :: GOLD
|
|
|
|
|
|
using vs 2008...
I'm trying to implement my own version of the standard library function:
#include <algorithm>;
copy( b, e, d ) ;
but, the line that calls 'my function' gives this error:
error C2668: 'copy' : ambiguous call to overloaded function
I'm guessing copy() is overloaded as it exists already in the standard lib...but I haven't included algorithm..so how would it know???
..also as a side note, if I change the name of 'my function' from copy to..it seems anything else
then I get the error:
error C2676: binary '++' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
from line:
*dest++ = *begin++;
--------------------------------
#include <string>
using std::string ;
template <class In, class Out>
Out copy( In begin, In end, Out dest )
{
while ( begin != end ) {
*dest++ = *begin++ ;
}
return dest ;
}
int main() {
string s = "the fox jumped over the moon" ;
string d ;
copy( s.begin(), s.end(), d ) ;
return 0 ;
}
|
|
|
|
|
You have two different problems.
The "++ error" comes from the fact that you send a std::string as the third parameter to copy. As the compiler says, std::string has no overloaded ++operator. You should instead use an output_iterator.
The name clash problem might come from another header including algorithm. Make use of the namespace qualifiers, and avoid using namespace std;
A good idea is to put your own copy function inside a namespace you choose.
|
|
|
|
|
Niklas Lindquist wrote: The "++ error" comes from the fact that you send a std::string as the third parameter to copy. As the compiler says, std::string has no overloaded ++operator. You should instead use an output_iterator.
doh ..how did i miss that
Niklas Lindquist wrote: The name clash problem might come from another header including algorithm. Make use of the namespace qualifiers, and avoid
using namespace std;<br />
<br />
A good idea is to put your own copy function inside a namespace you choose.<br />
ahh ..something new learned ..that worked a treat thanks
#include <string>
#include <iterator>
namespace custom{
template <class In, class Out>
Out copy( In begin, In end, Out dest )
{
while ( begin != end ) {
*dest++ = *begin++ ;
}
return dest ;
}
}
int main() {
std::string s = "the fox jumped over the moon" ;
std::string d ;
custom::copy( s.begin(), s.end(), std::back_inserter( d ) );
return 0 ;
}
|
|
|
|
|
tukbriz wrote: I'm guessing copy() is overloaded as it exists already in the standard lib.
Correct. Compiler shall show you where it find the ambiguity. Have a look into it.
tukbriz wrote: *dest++ = *begin++ ;
This statement makes the error, and the reason is clear - std::string class doesn't have ++ operator overloaded.
What are you exactly trying to do?
|
|
|
|
|
I have a problem about trying to change the color of selected/hilight row of CMFCListCtrl/CListCtrl when they are not in focus.
the control are already set with "full row select" styles
On windows xp or classic theme there is no problem.
but when using aero theme (both vista and 7) the color of selected row when it doesn't have a focus is a "very" light grey (opposed to darkgrey on old version of windows/classic theme)
that absolutely cannot be seen on my Laptop screen/LCD/50 inch HDTV.
I tried to implement the color changing by using custom draw but look like it impossible to change the selected cell/row color (only unselected cell/row color can be change). or it already
changed but the system draw the default selected background after custom draw,I dont know.
Please help me if anyone know the solution without resorting to full owner drawn implement (I dont have that much experience to recreate all the drawing code).
this is my current attemp which didn't work
void CMyListCtrl::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLVCUSTOMDRAW lpLVCustomDraw = reinterpret_cast<LPNMLVCUSTOMDRAW>(pNMHDR);
switch(lpLVCustomDraw->nmcd.dwDrawStage)
{
case CDDS_ITEMPREPAINT:
case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
if(this->GetItemState(lpLVCustomDraw->nmcd.dwItemSpec,LVIS_SELECTED) & LVIS_SELECTED){
lpLVCustomDraw->clrTextBk = RGB(0,0,0);
}
break;
default: break;
}
*pResult = 0;
*pResult |= CDRF_NOTIFYPOSTPAINT;
*pResult |= CDRF_NOTIFYITEMDRAW;
*pResult |= CDRF_NOTIFYSUBITEMDRAW;
}
|
|
|
|
|
Try doing this :-
if(this->GetItemState(lpLVCustomDraw->nmcd.dwItemSpec,LVIS_SELECTED) & LVIS_SELECTED){
lpLVCustomDraw->clrTextBk = RGB(0,0,0);
lpLVCustomDraw->nmcd.uItemState &= ~CDIS_SELECTED;
}
break;
I discovered this the other day after puzzling over a similar issue for months.
|
|
|
|
|
Holy ****, It work !!!
Thank a lot man,you just save my life.
Can you tell me why It has to remove (?) CDIS_SELECTED from the uItemState to make it work ?
|
|
|
|
|
I honestly don't know. I was debugging the CustomDraw message for some other reason, noticed the uItemState was set and cleared it. At which point I also said "Holy ****".
|
|
|
|
|
Hi all,
i m writing a excel sheet with use os excel automation and i m using this code its forking fine.
but the data alwayz write in sheet one ,i want to write in sheet 2 and also want to rename the sheet.
please tell me how can i do this.
thanks in advance.
HRESULT AutoWrap_Exp(int autoType, VARIANT *pvResult, IDispatch *pDisp, LPOLESTR ptName, int cArgs...)
{
va_list marker;
va_start(marker, cArgs);
if(!pDisp)
{
return 0;
}
DISPPARAMS dp = { NULL, NULL, 0, 0 };
DISPID dispidNamed = DISPID_PROPERTYPUT;
DISPID dispID;
HRESULT hr;
char buf[200];
char szName[200];
WideCharToMultiByte(CP_ACP, 0, ptName, -1, szName, 256, NULL, NULL);
hr = pDisp->GetIDsOfNames(IID_NULL, &ptName, 1, LOCALE_USER_DEFAULT, &dispID);
if(FAILED(hr))
{
sprintf(buf, "IDispatch::GetIDsOfNames(\"%s\") failed w/err 0x%08lx", szName, hr);
OutputDebugStringA(buf);
return hr;
}
VARIANT *pArgs = new VARIANT[cArgs+1];
for(int i=0; i<cArgs; i++)
{
pArgs[i] = va_arg(marker, VARIANT);
}
dp.cArgs = cArgs;
dp.rgvarg = pArgs;
if(autoType & DISPATCH_PROPERTYPUT)
{
dp.cNamedArgs = 1;
dp.rgdispidNamedArgs = &dispidNamed;
}
hr = pDisp->Invoke(dispID, IID_NULL, LOCALE_SYSTEM_DEFAULT, autoType, &dp, pvResult, NULL, NULL);
if(FAILED(hr))
{
sprintf(buf, "IDispatch::Invoke(\"%s\"=%08lx) failed w/err 0x%08lx", szName, dispID, hr);
OutputDebugStringA(buf);
return hr;
}
va_end(marker);
delete [] pArgs;
return hr;
}
void CTest_ExcelDlg::OnBnClickedButton2()
{
try
{
CString OpenFile_Name=_T("E:\\xl.xlsx");
CWaitCursor cwt;
DeleteFile(OpenFile_Name);
BOOL flag=FALSE;
int nRow=4;
int nCol=2;
CString locount;
locount.Format(_T("%d"),nRow+1);
CString rowp="";
rowp="A1:B";
rowp+=locount;
CString column="";
CString item="";
CoInitialize(NULL);
CLSID clsid;
HRESULT hr = CLSIDFromProgID(L"Excel.Application", &clsid);
if(FAILED(hr))
{
::MessageBox(NULL, _T("CLSIDFromProgID() failed"), _T("Error"), 0x10010);
return ;
}
IDispatch *pXlApp;
hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, (void **)&pXlApp);
if(FAILED(hr))
{
::MessageBox(NULL, _T("Excel not registered properly"), _T("Error"), 0x10010);
return ;
}
{
VARIANT x;
x.vt = VT_I4;
x.lVal = 0;
if(AutoWrap_Exp(DISPATCH_PROPERTYPUT, NULL, pXlApp, L"Visible", 1, x)!=S_OK)
{
flag=TRUE;
goto error;
}
}
IDispatch *pXlBooks;
{
VARIANT result;
VariantInit(&result);
if(AutoWrap_Exp(DISPATCH_PROPERTYGET, &result, pXlApp, L"Workbooks", 0)!=S_OK)
{
flag=TRUE;
goto error;
}
pXlBooks = result.pdispVal;
}
IDispatch *pXlBook;
{
VARIANT result;
VariantInit(&result);
if(AutoWrap_Exp(DISPATCH_PROPERTYGET, &result, pXlBooks, L"Add", 0)!=S_OK)
{
flag=TRUE;
goto error;
}
pXlBook = result.pdispVal;
}
VARIANT arr;
arr.vt = VT_ARRAY | VT_VARIANT ;
{
SAFEARRAYBOUND sab[2];
sab[0].lLbound = 1; sab[0].cElements = nRow+1;
sab[1].lLbound = 1; sab[1].cElements = nCol;
arr.parray = SafeArrayCreate(VT_VARIANT, 2, sab);
}
for(int i=1; i<=nRow+1; i++)
{
for(int j=1; j<=nCol; j++)
{
VARIANT tmp;
if(i==1)
{
if(j==1)
item=_T("Column 1");
else
item=_T("Column 2");
}
else
{
item.Format("Row :: %d and Column :: %d",i-2,j-1);
}
tmp.bstrVal = _bstr_t(item);
tmp.vt = VT_BSTR;
long indices[] = {i,j};
SafeArrayPutElement(arr.parray, indices, (void *)&tmp);
}
}
IDispatch *pXlSheet;
{
VARIANT result;
VariantInit(&result);
if(AutoWrap_Exp(DISPATCH_PROPERTYGET, &result, pXlApp, L"ActiveSheet", 0)!=S_OK)
{
flag=TRUE;
goto error;
}
pXlSheet = result.pdispVal;
}
IDispatch *pXlRange;
{
VARIANT parm;
parm.vt = VT_BSTR;
parm.bstrVal = ::SysAllocString(_bstr_t(rowp));
VARIANT result;
VariantInit(&result);
if(AutoWrap_Exp(DISPATCH_PROPERTYGET, &result, pXlSheet, L"Range", 1, parm)!=S_OK)
{
flag=TRUE;
goto error;
}
VariantClear(&parm);
pXlRange = result.pdispVal;
}
if(AutoWrap_Exp(DISPATCH_PROPERTYPUT, NULL, pXlRange, L"Value", 1, arr)!=S_OK)
{
flag=TRUE;
goto error;
}
{
VARIANT x;
x.vt = VT_I4;
x.lVal = 1;
if(AutoWrap_Exp(DISPATCH_PROPERTYPUT, NULL, pXlBook, L"Saved", 1, x)!=S_OK)
{
flag=TRUE;
goto error;
}
VARIANT result;
VariantInit(&result);
VARIANT fname;
fname.vt = VT_BSTR;
fname.bstrVal=::SysAllocString(_bstr_t(OpenFile_Name));
if(AutoWrap_Exp(DISPATCH_METHOD, &result, pXlSheet, L"SaveAs", 1, fname)!=S_OK)
{
flag=TRUE;
goto error;
}
}
if(AutoWrap_Exp(DISPATCH_METHOD, NULL, pXlApp, L"Quit", 0)!=S_OK)
{
flag=TRUE;
goto error;
}
error:
if(flag==TRUE)
{
AutoWrap_Exp(DISPATCH_METHOD, NULL, pXlApp, L"Quit", 0);
{
}
pXlRange->Release();
pXlSheet->Release();
pXlBook->Release();
pXlBooks->Release();
pXlApp->Release();
VariantClear(&arr);
CoUninitialize();
MessageBox(_T("Error in file."),_T("Message"),MB_ICONINFORMATION);
return ;
}
pXlRange->Release();
pXlSheet->Release();
pXlBook->Release();
pXlBooks->Release();
pXlApp->Release();
VariantClear(&arr);
CoUninitialize();
}
catch(...)
{
MessageBox(_T("Error in file."),_T("Message"),MB_ICONINFORMATION);
return ;
}
MessageBox(_T("Done."),_T("Message"),MB_ICONINFORMATION);
}
|
|
|
|
|
Instead of getting the "ActiveSheet" of pXLApp, get the "Worksheets" collection of pXLBook, then get "Item" 2 of that collection, that should give you the "sheet 2". Use a propertyput on the "Name" property of the Worksheet to change its name.
|
|
|
|
|
can u please explain it with example.
|
|
|
|
|
I use the Excel Dispatch Wrapper classes, which makes it much easier, this is exactly what I do in my own code
_Workbook m_excel_workbook;
Worksheets m_excel_worksheets;
_Worksheet m_excel_worksheet;
LPDISPATCH pdispatch;
LPCTSTR szSheetName = _T("name of sheet");
COleVariant varIndex((short)2);
pdispatch = m_excel_workbook.GetWorksheets();
if (pdispatch != NULL)
{
m_excel_worksheets.AttachDispatch(pdispatch);
pdispatch = m_excel_worksheets.GetItem(varIndex);
if (pdispatch != NULL)
{
m_excel_worksheet.AttachDispatch(pdispatch);
m_excel_worksheet.SetName(szSheetName);
}
}
Trying to fit that to your code would look something like this, I think
IDispatch* pXlSheets;
VARIANT result;
VariantInit(&result);
AutoWrap_Exp(DISPATCH_PROPERTYGET, &result, pXlBook, L"Worksheets", 0);
pXlSheets = result.pdispVal;
IDispatch* pXlSheet2;
VARIANT item;
result.vt = VT_EMPTY;
result.pdispVal = NULL;
item.vt = VT_I4;
item.lVal = 2;
AutoWrap_Exp(DISPATCH_PROPERTYGET, &result, pXlSheets, L"Item", 1, item);
pXlSheet2 = result.pdispVal;
VARIANT name;
name.vt = VT_BSTR;
name.bstrVal = ::SysAllocString("name of your sheet");
AutoWrap_Exp(DISPATCH_PROPERTYPUT, NULL, pXlSheet2, L"Name", 1, name);
|
|
|
|
|
Thanks its done with your help.
just one more query for this its working fine for default 3 sheets,
how can add new sheet and work for it?
thanks in advance.
modified on Monday, March 7, 2011 11:52 PM
|
|
|
|
|
How I do it :-
COleVariant varOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
COleVariant varCount((short)(2),VT_I2);
COleVariant varType((short)xlWorksheet,VT_I2);
pdispatch = m_excel_worksheets.Add(varOptional,varOptional,varCount,varType);
pdispatch->Release();
Fitted to your code, ( I think this will work given the quick comparison I did of your AutoWrap_Exp and MFC's InvokeHelper ) :-
IDispatch* pXlSheet2;
VARIANT optional;
result.vt = VT_ERROR;
result.lVal = (long)DISP_E_PARAMNOTFOUND;
VARIANT count;
count.vt = VT_I2;
count.iVal = 2;
VARIANT type;
type.vt = VT_I2;
type.iVal = -4167;
VARIANT result;
VariantInit(&result);
AutoWrap_Exp(DISPATCH_METHOD, &result, pXlSheets, L"Add", 4, optional, optional, count, type);
result.pdispVal->Release();
Access the extra sheets as before using propertyget "Item". Using optional for both Before and After means, if I recall correctly, the 2 new sheets are added to the end of the sheets collection.
|
|
|
|
|
thanks.
if i know how many row write in excel than its working fine and successfully write the excel file.
but when i write excel file from reading a text file so i dont know how many rows are need to be written so i am unable to create this array to assign value.
VARIANT arr;
arr.vt = VT_ARRAY | VT_VARIANT ;
{
SAFEARRAYBOUND sab[2];
sab[0].lLbound = 1; sab[0].cElements = nRow+1;
sab[1].lLbound = 1; sab[1].cElements = nCol;
arr.parray = SafeArrayCreate(VT_VARIANT, 2, sab);
}
please tell me this case how can i write the value in excel file
thanks in advance.
modified on Tuesday, March 8, 2011 3:10 AM
|
|
|
|
|
You could either :-
read the file once, counting the rows, create suitably sized array, read the file again filling in the values
or
read the file once, adding a single row to excel for each row in the file, stopping when there are no more rows in the file
|
|
|
|
|
thanks.
when the data of column is in form of multiline than its automatically display with wrap text option,how can i disable this.
modified on Wednesday, March 9, 2011 5:09 AM
|
|
|
|
|
I have a difficult question. In WM_CHAR: If i use IME: EN, i will receive corect code input char.(a:97). I use IME:Japan, Result is so(corect). When I select IME:VietNamese, Tamil...I received ?(code:63). Please help me.(I set location:japan)
|
|
|
|
|
I just recently tried to create a library and then use the library functions within a simple console application. I followed the instructions at:
http://www.functionx.com/visualc/libraries/staticlib.htm
After copying the "lib" and "h" file into the source file directory for the program, I got a linking error. I added these files to the project via "Add Existing Item" menu selection. The error I got was the following:
A custom build rule to build files with extension 'lib' could not be found.
Would you like to create a new rule to define a custom build rule to build files with this extension?
I would think that using library functions would be a standard functionality for Visual C. Is there a setting somewhere that has to be adjusted to allow for this functionality? If not, does anyone know the rule that needs to be used?
--------------------------------------------------------------------------------
|
|
|
|
|
You don't add the .lib file to the project, since it isn't a source file. Add the filename to the linker options, so it looks there for the library functions that you call.
--Mike--
Dunder-Mifflin, this is Pam.
|
|
|
|
|