|
Does anyone know how to instantiate an array in a __gc structure?
e.g
__gc struct epdata
{
__int61 count;
__int64 val __gc[]; // an array of integers
} x;
The compiler won't allow the array to be sized such as
__int64 val __gc[10]; // an array of integers
it gives this error message
e:\xf\Form1.h(12): error C3616: '10': a size cannot be specified in a __gc array declaration
This question came up when attempting to read data from the array that had been stored in the array previously.
e.g
x->val[0] = 2; // no error is generated on this line
__int64 y = x->val[0]; // this line gives " Object reference not set to an instance of an object."
|
|
|
|
|
You'll have to use new to allocate the array after the structure has been allocated.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
JimWDurbin wrote: x->val[0] = 2; // no error is generated on this line
Humble Request pls Post Managed C++ related Question in C++/CLI[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Thanks Alok, It has been a while since I posted anything at all. I did not know that is where question on Managed C++ questions should be posted.
BTW, after a lot of hacking, the problem has been resolved.
|
|
|
|
|
What is a good size for a buffer with the multi-select option for the OpenFileName Dlg? Right now it is 0x7FFF. Too much? Too little?
- thanks
|
|
|
|
|
|
Per MSDN:
Note, when selecting multiple files, the total character limit for the file names depends on the operating system and the version of the function:
Windows 95/98/Me: (only ANSI is supported) no restriction
Windows NT4 and earlier: 32k limit
Windows 2000/XP: (ANSI) 32k limit, (Unicode) no restriction
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
*******Update********
Thanks everyone, I found the problem...I mispelled the directory during one variable initialization. Thanks again for your help.
*******Update********
Everytime I run the code below (Visual Studio .NET 2003), it tells me that a debug assertion has failed. Then when I go into the code to debug it...it goes to "filecore.cpp" and points out the error in the following filecore.cpp function....
***************
void CFile::Write(const void* lpBuf, UINT nCount)<br />
{<br />
ASSERT_VALID(this);<br />
ASSERT(m_hFile != INVALID_HANDLE_VALUE); < - - - - **Debug Assertion Error**<br />
<br />
if (nCount == 0)<br />
return;
<br />
ASSERT(lpBuf != NULL);<br />
ASSERT(AfxIsValidAddress(lpBuf, nCount, FALSE));<br />
<br />
DWORD nWritten;<br />
if (!::WriteFile(m_hFile, lpBuf, nCount, &nWritten, NULL))<br />
CFileException::ThrowOsError((LONG)::GetLastError(), m_strFileName);<br />
<br />
if (nWritten != nCount)<br />
AfxThrowFileException(CFileException::diskFull, -1, m_strFileName);<br />
}
***********
The function wherein the problem occurs is as follows...
***********
<br />
void CGCS1View::OnFileSave()<br />
{<br />
UpdateData();<br />
<br />
CGCS1Doc *pDoc = GetDocument();<br />
<br />
CreateDirectory(_T("J:\\Software Development\\Georgetown Cleaning Serivces"), NULL);<br />
<br />
CTime DateLeft, TimeLeft, DateExpected, TimeExpected;<br />
this->m_DateLeft.GetTime(DateLeft);<br />
this->m_TimeLeft.GetTime(TimeLeft);<br />
this->m_DateExpected.GetTime(DateExpected);<br />
this->m_TimeExpected.GetTime(TimeExpected);<br />
<br />
CString strDate = DateLeft.Format(_T("%Y %B"));<br />
<br />
CString strPath = CString("C:\\Documents and Settings\\user\\My Documents\\Georgetown Cleaning Services\\") + strDate;<br />
CreateDirectory(strPath, NULL);<br />
<br />
CString strReceiptNumber = this->m_ReceiptNumber;<br />
CString strFileName = this->m_ReceiptNumber + ".gcs";<br />
CString strFilePath = strPath + CString("\\") + strFileName;<br />
<br />
CFileFind fndFile;<br />
BOOL exists = fndFile.FindFile(strFilePath);<br />
<br />
if(exists == TRUE)<br />
{<br />
AfxMessageBox("A file with that receipt number exists already\n"<br />
"Please enter a different receipt number");<br />
return;<br />
}<br />
else<br />
{<br />
CString strItem1, strItem2, strItem3, strItem4;<br />
this->m_Item1.GetWindowText(strItem1);<br />
this->m_Item2.GetWindowText(strItem2);<br />
this->m_Item3.GetWindowText(strItem3);<br />
this->m_Item4.GetWindowText(strItem4);<br />
<br />
pDoc->CustomerName = m_CustomerName;<br />
pDoc->CustomerPhone = m_CustomerPhone;<br />
pDoc->DateLeft = DateLeft;<br />
pDoc->TimeLeft = TimeLeft;<br />
pDoc->DateExpected = DateExpected;<br />
pDoc->TimeExpected = TimeExpected;<br />
pDoc->ShirtsUnitPrice = m_ShirtsUnitPrice;<br />
pDoc->ShirtsQuantity = m_ShirtsQuantity;<br />
pDoc->ShirtsSubTotal = m_ShirtsSubTotal;<br />
pDoc->PantsUnitPrice = m_PantsUnitPrice;<br />
pDoc->PantsQuantity = m_PantsQuantity;<br />
pDoc->PantsSubTotal = m_PantsSubTotal;<br />
pDoc->strItem1 = strItem1;<br />
pDoc->UnitPrice1 = m_UnitPrice1;<br />
pDoc->Quantity1 = m_Quantity1;<br />
pDoc->SubTotal1 = m_SubTotal1;<br />
pDoc->strItem2 = strItem2;<br />
pDoc->UnitPrice1 = m_UnitPrice2;<br />
pDoc->Quantity2 = m_Quantity2;<br />
pDoc->SubTotal2 = m_SubTotal2;<br />
pDoc->strItem3 = strItem3;<br />
pDoc->UnitPrice3 = m_UnitPrice3;<br />
pDoc->Quantity3 = m_Quantity3;<br />
pDoc->SubTotal3 = m_SubTotal3;<br />
pDoc->strItem4 = strItem4;<br />
pDoc->UnitPrice4 = m_UnitPrice4;<br />
pDoc->Quantity4 = m_Quantity4;<br />
pDoc->SubTotal4 = m_SubTotal4;<br />
pDoc->CleaningOrder = m_CleaningOrder;<br />
pDoc->TaxRate = m_TaxRate;<br />
pDoc->TaxAmount = m_TaxAmount;<br />
pDoc->OrderTotal = m_OrderTotal;<br />
pDoc->ReceiptNumber = m_ReceiptNumber;<br />
<br />
<br />
<br />
CFile fleOrder;<br />
<br />
fleOrder.Open(strFilePath, CFile::modeCreate | CFile::modeWrite);<br />
CArchive ar(&fleOrder, CArchive::store);<br />
pDoc->Serialize(ar);<br />
<br />
ar.Close();<br />
<br />
fleOrder.Close();<br />
<br />
UpdateData(FALSE);<br />
<br />
this->OnBnClickedReset();<br />
}<br />
<br />
}
***************
Any help you can provide would be greatly appreciated.
Thanks,
-- modified at 8:39 Monday 27th February, 2006
|
|
|
|
|
It's telling you the CFile object doesn't have a valid file handle. You're not checking the return values from CreateDirectory() or CFile::Open() - one or more of those are failing.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Thanks Mike. I'm going to check it out. Since it creates the directory, it must be that the CFile::Open() method is failing...although I wonder why.
|
|
|
|
|
It tells me that my m_cause = 0 and that OS Error = m_lOsError
What does that mean? This is, of course due to the open mehtod.
Thanks for any help you can provide
|
|
|
|
|
Hi,
Use GetLastError() to find the error code. Use the error code in error lookup tool to find the description. It may be a bad path error.
Bye,
Cool Ju
Dream Ur Destiny
|
|
|
|
|
I have a popup dialog. The user selects 1 of 3 checkboxes.
I want to transfer which checkbox the user selected back
to the point where I popup the dialog.
I have this:
CExampleDlg dlg;
if (dlg.DoModal())
{
int num = dlg.GetNum();
}
But I get an error ASSERT(::IsWindow(m_hWnd)) on the
dlg.GetNum() command which is:
int GetNum()
{
if (c_check1.GetCheck())
return 1;
else
return 0;
}
The error is on the line if (c_check1.GetCheck()). The
control c_check1 almost doesnt exist anymore.
Any idea what Im doing wrong. Please, any response any
one can give me will be greatly appreciated.
Sincerely,
Danielle (an overworked graduate student)
|
|
|
|
|
Why not just assign a value variable to the control on the dialog then pass that value? Also, if "GetNum()" appears exactly as you typed it, it has not been associated with the CExampleDlg class.
|
|
|
|
|
Can you give me an example of how to pass the value? Please, please.
The GetNum() is in the CExampleDlg class.
|
|
|
|
|
|
Hi DanYELL,
Declare CExampleDlg dlg;
in the function or in the class(Is it public)
|
|
|
|
|
DanYELL wrote: The user selects 1 of 3 checkboxes.
Shouldn't these be radio buttons instead?
In the dialog's OnOK() method, save the state of the buttons in a member variable. Then you can access that member variable after DoModal() returns.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
hi,
i got an .NET web application using C#,
that app talks to a C++ DLL that is using DAO,
when the first line get executed it throw an exception
, it only executes this line
CDaoWorkspace workspace;<br />
workspace.Open();
does any body have a clew, I know its not recommended to use DAO in any multithreaded application even on the desktop, but this is an legacy application and we want the minimum modification
Thanks
Lakani
|
|
|
|
|
What is the error text in the exception object?
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Its something about DAO can’t initialize, the error code is AFX_DAO_ERROR_ENGINE_INITIALIZATION , I can recall that we have to put something like initialization function before starting using DAO, is that right, but I can’t remember the syntax
|
|
|
|
|
Did you call AfxDaoInit() in your C++ code before you tried to use DAO?
Remember to call AfxDaoTerm() during your shutdown as well.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
It throws the same exception when I tried to do so,
I know that DAO is not working well in multithreaded environment, but I heard that this is fixed if I turn my DLL to UNICODE version, which I‘ve done, but still not working.
thanks Ryan,
|
|
|
|
|
Hi
am developing activex control, and in the OnDraw method i want to draw a round rectangle and fill it with gradient color
can you help me in that
thaks alot
Tarek Jabri
|
|
|
|
|
Try something like this:
------------------------
COLORREF Rainbow(int x)
{
enum
{
maximum = 255, // Range of x is from 0 to this value.
h1 = maximum/4,
h2 = maximum/2,
h3 = 3*maximum/4,
};
const double m = 255/h1;
BYTE red;
if ( x<=h1 )
{
red = 255;
}
else if (x>=h2)
{
red = 0;
}
else
{
red = static_cast<BYTE>(-m*x+510.0 + 0.5);
}
BYTE green;
if (x<h1)
{
green = static_cast<BYTE>(m*x + 0.5);
}
else if (x>h3)
{
green = static_cast<BYTE>(-m*x+1020.0 + 0.5);
}
else
{
green = 255;
}
BYTE blue;
if (x<=h2)
{
blue = 0;
}
else if (x>=h3)
{
blue = 255;
}
else
{
blue = static_cast<BYTE>(m*x-510.0 + 0.5);
}
return RGB(red, green, blue);
}
Steve
|
|
|
|