|
Flace wrote:
statically link the DLL
I think you've missed the point a little. DLL's are Dynamically Linked Libraries, they require dynamic linking. The .lib (static libraries) that you link to for implicit linking (at compile time) only forward responsibility to the DLL. Even if it is possible to statically link to a DLL (I personally don't know how too, but I'm sure there are hacks to do it) why would you bother??? Just distribute the DLL with your executable if you aren't sure whether the client has it.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
Ok, got it. Thanks.
but just curious as to how to statically link a library. for ex, wininet.lib. What should I do to statically link this?
Thanks,
Fl.
|
|
|
|
|
It depends a on which compiler and IDE you are using. One of the easiest ways in VC.NET is to add wininet.lib to the edit box:
Project Properties -> Linker -> Input -> Additional Dependencies.
Most IDE's should have something similar.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
How do I take an input(integer value) from a textbox than assign that input into an array. The array is a 50 element array.
int sum,val;
//int* average = new int[50];
//int average[50];// Create an array dynamically pg.234
String* i = VoltsTextBox->Text;
int averagr[val] = Int32::Parse(i);
|
|
|
|
|
What type of application are you working on? SDK or MFC?
Maxwell Chen
|
|
|
|
|
windows forms micosoft visual studio.net.
|
|
|
|
|
Right-click at the edit box control to add a data member of type int (for example, m_iMyVal). Then have a look at the function UpdateData(FALSE) to sync the value of m_iMyVal with the value (text) seen in that edit box. Finally you add the value into your array, and loop the step to complete the array.
Maxwell Chen
|
|
|
|
|
Hi
I have a problem with the thread and class.
I created a thread from a function and in the thread function, i called and init a class but not using the new and delete method. There is a problem when the thread ended as the class destructor was not activated when i called ExitThread...an example below
main function()
{
CreateThread(.....,ThreadProc,...);
}
ThreadProc()
{
CDB_Database Data(); //Class Init
DWORD dwRecords;
HANDLE hFile; etc
OpenFile();
...
....
...
ExitThread(0);
}
my problem is everytime i called creatThread, the class constructor will be activated but when i called ExitThread, the class destructor was not activated.
So is the resources used by the thread free when i called exitThread as i seems to have sharing violation inside the function
Thank you for ur advise
|
|
|
|
|
The ExitThread() function never returns, so the ThreadProc() doesn't reach its end and destructors don't get called. One way to solve this is to add another pair of braces:
ThreadProc()
{
{
CDB_Database Data();
DWORD dwRecords;
HANDLE hFile; etc
OpenFile();
}
ExitThread(0);
}
Now Data is destroyed when code exits the inner braces, just before ExitThread()
|
|
|
|
|
If the ThreadProc is declared as follows:
DWORD WINAPI ThreadProc(
LPVOID lpParameter // thread data
);
Why don't you just
return 0;
from your thread function instead of calling ExitThread at the every end of it anyway? Then your variables can go out of scope and destroy themselves automatically. Anything monitoring the 'exit code' of the thread will still see the 0.
FYI (From MSDN):
A thread that uses functions from the C run-time libraries should use the _beginthread and _endthread C run-time functions for thread management rather than CreateThread and ExitThread. Failure to do so results in small memory leaks when ExitThread is called.
|
|
|
|
|
fstream file;
char buffer[MAXBUFSIZE];
string line;
file.open(..., ios_base::in);
file.getline(buffer, MAXBUFSIZE-1);
//getline(file, line);
//both of the above fail to work
//and the vc.net2003 print such error info:
//error C2663: “std::basic_istream<_Elem,_Traits>::getline” : //2 //overloaded functions lack a legal conversion of pointer "this".
|
|
|
|
|
This works fine:
--------------------------------------
#include <iostream>
#include <fstream>
using namespace std;
void main()
{
fstream file;
const int MAXBUFSIZE = 256;
char buffer[MAXBUFSIZE];
file.open("a.txt", ios_base::in);
do
{
file.getline(buffer, MAXBUFSIZE-1);
//getline(file, line);
string s = buffer;
cout << s.c_str() << endl;
} while (! file.eof() );
}
<b>Maxwell Chen</b>
|
|
|
|
|
Might I suggest something more like this:
#include <iostream>
#include <fstream>
#include <string>
int main() {
std::ifstream file("filename");
std::string line;
while (std::getline(file, line)) {
std::cout << line << '\n';
}
return 0;
}
Just a couple of points:
- C++ defines main as: "int main()" or "int main(int argc, char* argv[])". There's nothing in the code that limits us to Visual C++ and its non-standard "void main()" extension.
- Using std::getline (defined in "string") we avoid using a char* buffer as we have to with std::basic_istream<...>::getline.
- Invoking s.c_str() on something we write out using iostreams anyway might incur the following overhead: a char* buffer that can contain the contents is allocated, the contents of s is copied over into it, a terminating null character is added and this buffer is returned. This is because the contents of std::string isn't guaranteed to be null terminated.
Hope this helps.
--
Henrik Stuart (http://www.unprompted.com/hstuart/[^])
|
|
|
|
|
thank you for the response.
Finnally, I figured out the key problem.
the fstream object is the data member of my
class not declared mutable, but in the member
function declared const, the fstream.getline()
failed.
//ps: the error information vc.net2003 offers me
//just confuses me
|
|
|
|
|
Henrik, you got my 5!
Basically I agree with all of your view points, and they are quite true. It reminds me to pay efforts in studying the Standard Library.
Regarding to the prototype of main, you are right too, as we don't find any 'void main()' in Stroustrup's book. It's just my bad custom for simplicity, since in the MSDN Library it is stated:
Alternatively, the main and wmain functions can be declared as returning void (no return value). If you declare main or wmain as returning void, you cannot return an exit code to the parent process or operating system using a return statement; to return an exit code when main or wmain is declared as void, you must use the exit function.
Anyway, I like your attitude!
Maxwell Chen
|
|
|
|
|
thank you for the response.
Finnally, I figured out the key problem.
the fstream object is the data member of my
class not declared mutable, but in the member
function declared const, the fstream.getline()
failed.
//ps: the error information vc.net2003 offers me
//just confuses me
|
|
|
|
|
I have a class ( CPolyBtn)
This Function the PreSubclassWindow() allow . When the only one framework then the project is ok. But When I have two frameworks then the project is a error in this Function ASSERT(0). I don’t process. You help me.
void CPolyBtn::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class
ModifyStyle(0, BS_OWNERDRAW);
if (m_edges.size()==0)
{
ASSERT(0);
}
else
{
m_rgn.DeleteObject();
SetWindowRgn(NULL, FALSE);
m_pPoints = new POINT[m_edges.size()];
for (int i=0;i<m_edges.size();i++)
{
="" m_ppoints[i]="m_edges.at(i).start;
"
="" if="" (i="">0)
{
ASSERT(m_edges.at(i-1).end == m_edges.at(i).start);
}
}
m_rgnWnd.CreateRectRgn(0,0,0,0);
// couldn't find a way to expand a region. so, we'll
// offset the region in 8 directions and combine the
// results. yes, this is a hack.
CRgn temp;
temp.CreatePolygonRgn(m_pPoints, m_edges.size(), ALTERNATE);
temp.OffsetRgn(-1,0);
m_rgnWnd.CombineRgn(&temp, &m_rgnWnd, SIMPLEREGION);
temp.OffsetRgn(0,1);
m_rgnWnd.CombineRgn(&temp, &m_rgnWnd, SIMPLEREGION);
temp.OffsetRgn(1,0);
m_rgnWnd.CombineRgn(&temp, &m_rgnWnd, SIMPLEREGION);
temp.OffsetRgn(1,0);
m_rgnWnd.CombineRgn(&temp, &m_rgnWnd, SIMPLEREGION);
temp.OffsetRgn(0,-1);
m_rgnWnd.CombineRgn(&temp, &m_rgnWnd, SIMPLEREGION);
temp.OffsetRgn(0,-1);
m_rgnWnd.CombineRgn(&temp, &m_rgnWnd, SIMPLEREGION);
temp.OffsetRgn(-1,0);
m_rgnWnd.CombineRgn(&temp, &m_rgnWnd, SIMPLEREGION);
temp.OffsetRgn(-1,0);
m_rgnWnd.CombineRgn(&temp, &m_rgnWnd, SIMPLEREGION);
// once you use a region in SetWindowRgn, you're not allowed to do *anything* else with it
// so, we'll make a copy.
m_rgn.CreateRectRgn(0,0,0,0);
m_rgn.CopyRgn(&m_rgnWnd);
SetWindowRgn(m_rgnWnd, TRUE);
if (m_bmpID!=0)
{
if (!m_bmp.LoadBitmap(m_bmpID))
{
ASSERT(0);
}
}
if (m_bmpIDD!=0)
{
if (!m_bmpD.LoadBitmap(m_bmpIDD))
{
ASSERT(0);
}
}
}
CButton::PreSubclassWindow();
}
Hello
|
|
|
|
|
i've got this code
FILE *tempf
std::string s;
arch=fopen(tempf,"r+");
cout <<"enter your name";
cin >>s;
fprintf(arch,s);
the last line doesn't compile. It says it can't convert from ...std::string.. to char *
any ideas?
thanks!
|
|
|
|
|
|
#include <iostream>
#include <fstream>
#include <string>
std::string s;
std::ofstream arch("filename");
std::cout << "enter your name: ";
std::getline(std::cin, s);
arch << s;
Reading the name by using "cin >> s;" will stop at the first whitespace character, so if you want to read the entire line std::getline is just perfect. std::getline strips the newline characters from the end (both \r and \n).
Personally find mixing C and C++ I/O a tad on the ugly side. I'm fully aware that it can be a necessity when incorporating C++ code in older apps, but for new code you might as well stick to the iostream library.
I haven't included any error checking in the above code (those are the things we love to leave as an exercise for the reader, no?). All it needs more, really, is a check on whether the file was actually opened and good for writing.
Hope this helps.
--
Henrik Stuart (http://www.unprompted.com/hstuart/[^])
|
|
|
|
|
kfaday wrote:
arch=fopen(tempf,"r+");
What is this? The first parameter to fopen() is a const char* filename, and the return value is a FILE* . Something like:
tempf = fopen("myfile.txt", "r+");
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I am write a program that has two buttons. The first button would read an int value from a textbox and loads the value into an array. Both of the buttons should take the program execution from the button presses to a single method. The array holding the data should be declared locally in this method. The array is 50 elements long. When Calculate Average button is pressed,and pass the array and the count of the number of items in the array to a separate method that will perform the averaging and display the average value of the array in a label.
Wow, I hope you not a sleep after all that... Okay, I have the buttons,the textboxes, the only problem I am having and need help with is taking the input from the textbox, then assign it to array and the caculate the average.. Thank You for the Help....
|
|
|
|
|
You need to pass the array as a pointer, and then you're right, you need to pass a count as well. Or you can use a vector, which you can pass by reference.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I am stuck. I can not get the average if the inputs and I am not sure if the value are add up. Here is what I have so far... If you need to see my whole program just let me know.
void MyForm:: Btn1_Clicked(Object* sender, EventArgs* e)
{
int i,sum;
int* average = new int[50];// Create an array dynamically pg.234
String* average1 = VoltsTextBox->Text;
int val = Int32::Parse(average1);
for(i=0; i<50; ++i)
{
average[i];
}
for(i=0; i<50; ++i)
{
sum = sum + average[i];
}
int ave = sum/i;
String* ave2= ave.ToString("F3");
CurrentTextBox->Text= ave2;
}
|
|
|
|
|
I would expect something like,
class MyForm
{
private :
...
int values [ 50 ] ;
int value_count ;
public :
MyForm () : value_count ( 0 )
{
...
}
void Btn1_Clicked(Object* sender, EventArgs* e)
{
if ( value_count < 50 )
{
values [ value_count ] = GetValueFromBox () ;
++value_count ;
}
}
void Btn2_Clicked(Object* sender, EventArgs* e)
{
int sum = 0 ;
for ( int c = 0; c < value_count; ++c )
{
sum += value [ c ] ;
}
SetValueInBox ( sum / value_count ) ;
}
...
} ;
But if I were doing it I'd use a vector so as not to have any arbitrary limit on number of values.
The code above doesn't fit your requirements, but your requirements seem perverse. I don't understand why you are asked to make the array local to the method, this just seems to be requiring bad code. You would have to make the array and the count static, and then how does the 'average' button method know how to find the data?
Paul
|
|
|
|
|