|
can u tell me about heap..(memory allocate)
i'm just small programmer.
so,i can't handle.
how can i keep?
|
|
|
|
|
Basically, memory allocated by a DLL should be freed by that DLL (not by your EXE). And vice-versa.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
And therein lies the rub. What Roger was pointing out is exactly what's happening. When adding the CStringArray has strings added to it in the DLL, the guts of the CString s inside the CStringArray are allocated by the DLL. But then the CStringArray goes out of scope in the application, the app tries to free it from the heap. Hence, the error
By the way, this particular error can occur when you overflow an allocated block. Ten gallons of crap doesn't fit in a five gallon bucket (feel free to convert to liters ).
Bob Ciora
|
|
|
|
|
can i pass CStringArray from dll.
example...
CStringArray my(void)
{
CStringArray a;
---
a.Add("a");
a.Add("b");
a.Add("c");
a.Add("d");
--
return a;
}
i can not pass CStringArray from dll.
error C2558: class 'CStringArray' : no copy constructor available
i don't know.
how can i control CStringArray in dll?
|
|
|
|
|
vc-programmer- wrote:
can i pass CStringArray from dll.
Yes, by reference, as in:
void my (CStringArray& theArray)
{
theArray.Add ("a");
theArray.Add ("b");
...
return;
}
However, this won't fix the problem, since the contents of theArray will be freed by the client app and not by the DLL as they should. Consider offering another method in your DLL that will clear the CStringArray 's contents. Also consider building a static library instead of a DLL.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
I want to use method below to manapulate database:but how can I get the specified interface ,for example:_ConnectionPtr.
IDispatch* pDispatch=NULL;
CLSID clsid;
CoInitialize(0);
HRESULT hr = ::CLSIDFromProgID(L"ADODB.Connection", &clsid);
if(FAILED(hr)){return;}
CoCreateInstance(clsid, NULL, CLSCTX_SERVER, IID_IDispatch, (void **)
&pDispatch);
if(FAILED(hr)){return;}
thanks a lot
|
|
|
|
|
Click on 'My Articles' link in my signature and go to my BugReporter article. See described in the article how I use #import to use ADO in my app, or look at the comments posted below my article on how to use LIBID (if you're using VC7).
Better yet, BugReporter[^]
My articles
www.stillwaterexpress.com
BlackDice
|
|
|
|
|
thanks for your help,but I want to use this method without importing ado.dll:
CString m_strConnect.Format("Provider=OraOLEDB.Oracle.1;Password=user_password;Persist Security Info=True;User ID=user_id;Data Source=user_DATASource;");
_RecordsetPtr m_prs;
_ConnectionPtr m_pConnection;
HRESULT hr = S_OK;
try
{
hr = m_prs.CreateInstance(__uuidof(Recordset));
if(FAILED(hr))
{
AfxMessageBox("记录集对象建立失败!",MB_ICONINFORMATION);
return ;
}
BeginWaitCursor();
m_strSQL = "select * from tableA";
hr = m_prs->Open(_bstr_t(m_strSQL),(IDispatch*)m_pConnection,adOpenStatic ,adLockReadOnly,adCmdText);
if(FAILED(hr))
{
AfxMessageBox("数据库查询失败!",MB_ICONINFORMATION);
return ;
}
EndWaitCursor();
}
catch(_com_error e)
{
CString errormessage;
errormessage.Format("错误信息:%s",(char*)(e.Description()));
AfxMessageBox(errormessage, MB_ICONINFORMATION);
return;
}
catch (CException err)
{
err.ReportError();
return;
}
catch(...)
{
AfxMessageBox("未知错误!",MB_ICONINFORMATION);
return;
}
compiles show errors:_ConnectionPtr not definition
|
|
|
|
|
i use spin control to spin a opengl dialog box based aplication (rectangle object), i put info about spin control value to a static text, i set range from -90 to 90, it's run normal wen run from 90 - 0(left to right(clock arrow)), but when value -1 (on static text info) the rectangle object JUMP BACK from 0 position back to aprox ~ +20 (JUMP BACK right to left(back of clock arrow)) then at -2, -3, -4 ... etc run continue from -1 position from left to right(clock arrow again),
somebody help me please , or can you help me code to run spin control to move/spin object on a opengl dialog box aplication.
|
|
|
|
|
i use spin control to spin a opengl dialog box based aplication (rectangle object), it put info about spin control value to a static text, i set range from -90 to 90, it's run normal wen run from 90 - 0(left to right(clock arrow)), but when value -1 (on static text info) the rectangle object JUMP BACK from 0 position back to aprox ~ +20 (JUMP BACK right to left(back of clock arrow)) then at -2, -3, -4 ... etc run continue from -1 position from left to right(clock arrow again),
somebody help me please , or can you help me code to run spin control to move/spin object on a opengl dialog box aplication. ???
|
|
|
|
|
I have to write a program to turn off the hard disk immediately.
Is there any Windows API for controlling the hard disk?
I surf on the internet, and I got a utility - Hard Disk Sleeper.
It can turn off hard disk immediately.
Does anybody know how it achieves that?
Thanks !
Jesa
|
|
|
|
|
My first guess would be to create a (temporary) policy using CallNtPowerInformation() . Set the SpindownTimeout member of SYSTEM_POWER_POLICY to 0.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I look up the MSDN, this way can not turn off hard disk immediately.
When we set the SpindownTimeout to "0" ,then the result is set to "Never".
It seems that the minimum value of SpindownTimeout is 180 (3 mins).
Jesa
|
|
|
|
|
Are your results from actual testing or some Internet site? I found SpindownTimeout mentioned in only one place in MSDN. While it makes no mention of 0, which could very well mean "never," a one-second delay would not be noticeable.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I have checked several pages on here and on other sites about returning values from calling a dialog. Some sites say "use UpdateData" and others say "don't use UpdateData". I try both ways and neither of them work so either I'm not implementing either way right or there's a third way I don't know. Here's the DoDataExchange function that's in the dialog that I call (the child):
void CCompressionTest::DoDataExchange(CDataExchange* pDX) {<br />
CDialog::DoDataExchange(pDX);<br />
DDX_Control(pDX, IDC_DOUBLE_COMBO, m_doubleComboBox);<br />
DDX_Control(pDX, IDC_SINGLE_COMBO, m_singleComboBox);<br />
DDX_Radio(pDX, IDC_SINGLE_RADIO, m_compressionRadio);<br />
}
Here's the code where it's called by the parent and then used:
CCompressionTest dialog;<br />
if (dialog.DoModal()) {<br />
CString message;<br />
message.Format("val1: %u\nval2: %u\nval3: %u", dialog.m_compressionRadio, dialog.m_singleComboInt, dialog.m_doubleComboInt);<br />
AfxMessageBox(message, MB_OK);<br />
}
When I type "dialog.", the variables show up in the list so I know it is aware of the variables, but the result is all zeroes. I've spun my wheels for long enough and I am asking for help. Thanks in advance, Nate.
|
|
|
|
|
The second two variables you're printing out aren't in the data exchange list, so they won't have any data in at all. The first should have though. Have you tried selecting different radio buttons and seeing what is printed out?
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"
|
|
|
|
|
I added the two variables under "Add Variables...", they are public shorts and thought it was more automatic than that. How do I add the second two variables? I thought when I added them, it sent them through like it should with the radio button? Yes I've tried other radio buttons, I only have two so I guess that's why it's a boolean value instead of integer.
edit: I added two new variables, they were private value integer variables but I just moved their declarations from private to public. They can now tell me which numbered item was selected which I can deal with. However, the radio button is still not working. I go to the Add Variables wizard but it still keeps forcing me to choose a boolean value for the radio buttons and changing the selection doesn't seem to change the value of the radio button variable.
|
|
|
|
|
LighthouseJ wrote:
Some sites say "use UpdateData" and others say "don't use UpdateData".
Calling UpdateData() manually can invite lots of problems. When it's called automatically by OnOK() , that's fine.
What types are m_compressionRadio , m_singleComboInt , and m_doubleComboInt ? Can you verify that the three statements in DoDataExchange() are being called after the OK button has been clicked?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thank you for your response. I fixed the combo values with the other reply in this thread and just now I realized that I set the "Group" property for both radio buttons but remembered only the radio that has the member value that will be returned should have the Group property set. The results fully work now, thanks again.
|
|
|
|
|
Hey all,
I've been toying with making a TCP connection and sending and receiving strings for a couple of days now. I've finally gotten to the point where I can initiate a connection, send some data, and receive some data (I pretty much have a WHILE loop in there listening for certain strings coming back). I'm doing it in the manner of:
CSocket mySocket;
if (mySocket.Connect("192.168.1.105",2000)) {
// while ...
// mySocket.Send();
// mySocket.Receive();
}
All I'm using is CSocket::Connect, Send and Receive. It's working great. I've been stuck for a day now on how to detect when that socket has been closed. (IE, I physically disconnect the LAN cable on the 192.168.1.105 PC). I cannot figure out how to do this. I've read a bunch of articles, and I simply cannot get it to work. I was hoping there was some sort of " if mySocket.IsStillOpen() .... " method existed, but I cannot find one. I'm not sure how to proceeed and was looking for a pointer in the right direction. Any help is extremely appreciated, as this has been a long road to do what seems to be a simple task (I guess I'm a slow learner!)
Thanks much in advance
|
|
|
|
|
I'm not an expert here but the OnSend member should return a value of WSAENOTCONN if you try to send data to a remote you're not connected to. I'm sure it will return something other than success if the cable is unplugged during the transmission. Are you checking return values?
|
|
|
|
|
Sometimes, if I do mySocket.Receive ..... and the socket disconnects (ie, I do a mySocket.Receive... and the socket is still connected, but the remote end has not sent anything ... and I disconnect the LAN cable, dropping the connection ...) the program just sits and hands on the mySocket.Receive() code. (I have a "MessageBox()" before and after the receive statement, so I can tell that it gets to there, and then it's like it tries to listen for data, even though the connection has failed, and never exits out of that receive method. I'm wondering how I can get around this??
|
|
|
|
|
|
Unplugging the network cable doesn't close a socket. Plug the cable back and data transfer should continue, TCP/IP is designed to handle unreliable physical connections.
|
|
|
|
|
hi,
on my application i have lib file for toolbar and i want host( attach ) this lib file to Internet Explorer but i dont know how
thanks
|
|
|
|