|
If you are only new to C++ (as opposed to being new to programming), I can recommend "Accelerated C++" by Koening/Moo.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
I found the problem!!!
I Replaced the critical sections by local variables CMutex and it solve the problem. But more strange is the fact that if I remove the CMutex object, it is still working I have no acces conflict!
So I don't really understand the utility of critical sections since my threads looks smart enough to wait for each other to finish accessing the shared variables...
(NB: I found this AFX_THREADPROC synthax in the MSDN.)
Thanks a lot for your time Diddy and have a nice evening!
|
|
|
|
|
"local variables" as in local to the functions?! Unless they are named mutexes you will be unlocking and locking different mutexes.
"smart enough to wait for each other to finish accessing the shared variables...".......... Hee hee.... Well, run it 100 times and 80 of them might work, but threads are threads and if they are both reading and writing to the same shared data, without any syncronisation objects, you are asking for trouble. Unless the operations to do the reading and wring are single step operations, for example u are much less likley to runinto trouble sharing a simple int (the worst that could happen is you get the wrong value) as to a shariing a string - which is a multistep opeation and you one thead could pre-empt the other halfway through the process.
The casting to AFX_THREADPROC ? Very strange, I've always seen it as LPVOID then cast in the thead - function pointer casting makes me nervous
Anyway, if it works, who cares!
Have a nice evening yourself
|
|
|
|
|
I'm attempting to use the oralib Oracle OCI wrapper library in my VC++ 6.0 project. It's giving me a number of linker errors (see below).
Has anyone used this library successfully?
Thanks!
--------------------Configuration: RAD_DataAnalysis - Win32 Debug--------------------
Linking...
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >(void)" (??1?$basic_strin
g@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in oralib.lib(statement.obj)
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::out_of_range::out_of_range(class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> > const &)" (??0out_of_range@std@@QAE@ABV?$basic_string@DU?$char_tr
aits@D@std@@V?$allocator@D@2@@1@@Z) already defined in oralib.lib(statement.obj)
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >(char const *,class std::a
llocator<char> const &)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBDABV?$allocator@D@1@@Z) already defined in oralib.lib(statement.obj)
LIBCMTD.lib(fpinit.obj) : error LNK2005: __ldused already defined in a previous module
LIBCMTD.lib(fpinit.obj) : error LNK2005: __fltused already defined in a previous module
LIBCMTD.lib(dbgheap.obj) : error LNK2005: _malloc already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(crt0dat.obj) : error LNK2005: __exit already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in msvcrtd.lib(cinitexe.obj)
LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in msvcrtd.lib(cinitexe.obj)
LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in msvcrtd.lib(cinitexe.obj)
LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in msvcrtd.lib(cinitexe.obj)
LIBCMTD.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(dosmap.obj) : error LNK2005: __errno already defined in msvcrtd.lib(MSVCRTD.dll)
msvcrtd.lib(MSVCRTD.dll) : error LNK2005: __setmbcp already defined in LIBCMTD.lib(mbctype.obj)
LINK : warning LNK4098: defaultlib "msvcrtd.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib "LIBCMTD" conflicts with use of other libs; use /NODEFAULTLIB:library
LIBCMTD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/RAD_DataAnalysis.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
RAD_DataAnalysis.exe - 17 error(s), 2 warning(s)
|
|
|
|
|
Looks like the objects in oralib.lib are linked to the static multithreaded version of the C runtime library, but your project is configured to use the DLL. Change your project to use the debug multithreaded version, or obtain a version of oralib.lib which uses the DLL.
To change this setting, go to Project > Settings, the C/C++ tab, change the Category drop-down to Code Generation, then under 'Use run-time library' select Debug Multithreaded.
|
|
|
|
|
I am working on a toolbar in IE, which is a COM DLL. There is one instance of the toolbar for each IE window. I'd like to know how to find out the relationship in between. For exampe, if I know the HWnd of an instance of toolbar, how can I know the HWnd of its IE window? I tried GetParent of my toolbar instance. It is not working. I also tried (HWND) GetWindowLong (hWnd, GWL_USERDATA). Still not working.
Please help me.
Thanks a lot in advance.
|
|
|
|
|
I've never done any database project and I dont' know how to start. I saw several article about database using c++.net, ADO.net, VB.net,..etc they really confused me.
if I want to create the sample table using MS Access, how? I read some article on Microsoft.com about ADO is better than Automation MSAccess. But I just don't see any article about how to start or begin, creating a simple table with MS Access.
which language I should use c++, vb, or c#. I'm using .Net
and Can you please guide me how to begin please...
thank you
|
|
|
|
|
There is no 'best' language for a database project; it is more dependant on the target platform.
If you are programming for a web page, then PHP is the thing to choose, but if you're attempting to create desktop software with database access, I suggest dwelving into ODBC and MFC's support for ODBC (CDatabase, CRecordset & CRecordview).
Here's a link to the MSDN Library site for database programming with MFC[^].
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Created a Dialog application last night with Menu, one of the choices in the menu is another dialog window which I created a separated class for. However tried to initialise the dialog, but unable to do so. (Note: that this dialog has a FlexGrid and this is what I'm trying to initialise)
Suggestions much appreciated
Kind Regards
Caoimh
|
|
|
|
|
Please be a little more specific. What do you mean with "tried to initialise the dialog"?
Usually you open a new dialog in a dialog based app like this:
At the top of the file:
#include "MySecondDlg.h" At the place where you want to open the dialog:
CMySecondDlg dlg;
dlg.DoModal(); That's it...
Regards, mYkel
|
|
|
|
|
I've done it exactly as you indicated but what if you want to initialise values in a Grid like FlexGrid or even an edit box?
Kind Regards
Caoimh
|
|
|
|
|
All initialisations of a dialog are usually done in the OnInitDialog() method.
The method OnInitDialog() gets called before a dialog is shown.
So just start the dialog as you have done it already and handle OnInitDialog()
in your CMySecondDlg(). Here's a short example:
MyFirstDlg.cpp:
#include "MySecondDlg.h"
...
CMySeconDlg dlg;
dlg.DoModal() MySecondDlg.cpp:
BOOL CMySecondDlg::OnInitDialog()
{
...
myEditBox = "Just an example..."
UpdateData(FALSE);
} Normally the OnInitDialog() message handler is create by default, so you just have to add your initialisations like above. Otherwise you have to create this message handler by yourself.
Regards, mYkel
|
|
|
|
|
hi all,
i did never care that much about unicode, WCHAR, T_(), UTF-X and all these character-width things. but now someone wants to have an UTF-8-encoded string from my application.
so now i'm sitting here for hours reading FAQs and postings and still haven't found the
<br />
CString::ToUtf8( BYTE *pUtf8String, long &nSize)
function. where is it?
for real: what's the easiest way to just get that CString i have into UTF-8? (my app is compiled without _UNICODE - so the chars in the CString are all 8 bit wide).
tia
:wq
|
|
|
|
|
I belive you are back to Win32 here.
Use MultiByteToWideChar to convert the string, specifying CP_UTF8 as the code page.
Store the result in a WCHAR array and from that point on I think you are without your faitful CString, in .NET there is a CStringW and CStringA that you can explicatly use or a normal CString which is set depending on the _UNICODE define, but not in VC6.
You could always try STL - string and wstring.
|
|
|
|
|
but MultiByteToWideChar() doesn't construct a UTF-8 encoded string, does it? afaik the point in UTF-8 is that characters < 0x7F are still only 8bit wide.
btw: i'm on VS.NET 2003 if that makes any difference.
:wq
|
|
|
|
|
MultiByteToWideChar(CP_ACP, );
WideCharToMultiByte(CP_UTF8, ); The first converts the code page your thread is running on into UTF-16 (2 byte Unicode encoding). This is necessary to get the canonical Unicode values. The second performs the fairly simple transform from UTF-16 to UTF-8.
Of course, if you're sure you'll only ever be using the ASCII character set, you already have UTF-8, since the first 128 characters are a direct map. Since you have an accent in your name, though - ü is ANSI code 252 (and also Unicode U+00FC) - I assume you'll need the proper technique.
|
|
|
|
|
yup thx. i just figured out how to use Wide...()
CStringW str("äö€èéß");
long size = str.GetLength()*6+1;
char *out = new char[size];
if (!WideCharToMultiByte(CP_UTF8,0,str,-1,out,size,NULL,NULL))
{
DWORD err = GetLastError();
}
delete [] out;
*6 is a bit exaggerated, but you never know - memory is cheap nowadays
i'll use that multitowide-function too - thx for your reply. things look way smoother now
:wq
|
|
|
|
|
I testing C++ application:
I install second Win2000.
Made local disk available for both,
but when I change directory in base OS,
disk content in second OS remains not changed.
So question - how to make interact OS-es
through hard disk ?
thanks.
|
|
|
|
|
Hi all,
How do i control the actions(capturing mouse and keyboard events) and disabling some menu items in IE?
Thanks in advance,
AL
|
|
|
|
|
Hi, I have a logging class which contains a <code>static std::map</code> of logfilename to std::ofstream, so that I can ensure every logging object uses the correct stream.
When I first attempt to access the map in any way, by calling <code>insert()</code> or anything else, I get an Access Violation from within STL. Has anybody come across this before, or am I missing something obvious?
My classes are outlined as follows:
<code>class LogThis
{
public:
LogThis(const std::string& logName);
~LogThis();
...
private:
...
static std::map<std::string, LogFileStream> mLogFileStreams;
};</code>
Where LogFileStream is just a simple class with a pointer to an std::ofstream and a reference counter of how many logging objects are using the stream, so I know when I can close the stream and delete the pointer.
The logging class is contained within a static lib and I am using Visual Studio.Net.
Any help would be much appreciated.
Thanks,
Christopher
The bomb lives only as it is falling
|
|
|
|
|
How have you then "declared" this static variable (mLogFileStreams? By that I mean in the CPP for the class, you will have something to initialise the map, like this:
std::map<std::string, LogFileStream> LogThis::mLogFileStreams;
What have you got there?
Try a simple test, change the map to map "simple" types, ie map int-to-int, that way you can pinpoint the problem a bit more to either the LogFileStream class causing the map problems, or the map itself.
|
|
|
|
|
Yes, I initialise it at the top of my cpp file, otherwise it wouldn't compile.
std::map<std::string, LogFileStream> LogThis::mLogFileStreams = std::map<std::string, LogFileStream>();
I also tried just this:
std::map<std::string, LogFileStream> LogThis::mLogFileStreams;
But it didn't seem to make any difference. Anyway, I shall experiment with some primitive types and report back.
The bomb lives only as it is falling
|
|
|
|
|
<small><b>simcoe23 wrote:</b></small>
<i>Yes, I initialise it at the top of my cpp file, otherwise it wouldn't compile.</i>
Note is says "how have you" not "have you"
Anyway, std::map definatly do work as static memebers, so it's probably something with your other class. For instance this works without problem
typedef map<int, int> MYMAP;
class A
{
public:
static MYMAP aMap;
};
MYMAP A::aMap;
int main(int argc, char* argv[])
{
A aa;
aa.aMap.insert(MYMAP::value_type(3, 3));
return 0;
}
|
|
|
|
|
Hi there, sorry I didn't notice the "how have you" .
I just tried with a std::map<int,int> and exactly the same thing happens.
The map.insert code is being called in the constructor of my main class, might that be a problem? Basically you create this logging object by passing a filename into the constructor, it checks if the file stream is already open, if not it opens a new stream and stores it in this static map using the filename as a key.
The other thing to mention is that the logging object which is being constructed is a global - I declare it using 'extern' at the bottom of my header file, which may or may not be the right thing to do.
The bomb lives only as it is falling
|
|
|
|
|
Yes - Maybe
The important bit is "logging object which is being constructed is a global " does this mean that the class that is using the map, which is static, is also being declared as global? Or does it mean the logging class which uses the map is declared global, then you have another "main" class that uses the logging one, which isn't global?
When your app starts up, the C runtime libray will init all your static and global members and doesn't do these in any perticualr order - when your constructor calls insert on the map, it's likley that the map hasn't been created yet.
Comment out the line that insert's into the map into the ctor, put a break point in your classes ctor, when it gets hit, check the call stack and go back to the _inititem functions - this is the CRT calling the ctors for all your global variables. Step back out of your ctor to this loop, and you should see that the loop then go into the ctor for the map - IE the map is being created after your ctor is being called, and you get a AV.
You could have a Init() method on your logging object or something, there are a few soultions to this problem really.
|
|
|
|
|