ReadDirectoryChangeW Problem
Hi All,
I have written a code for directory watching.All is working fine. But i got
two small issues.
1. when i add any file in watching directory. i got 4 notifications 1 for
file added and 3 for file modified.
2. How can i determine any file has been successfully copied in watching
directory.
because during copy i got 3 notification. 1 for file added and 2 for file
modified. and after successfully copy i got one file modified notiifcation.
thanks in advance.
--
With regards
thanks
Anand Choubey Tag: test Tag: 251863
Writing to parallel port
Hello
How can i write something to parallel port ?
I use windows XP and .NET, but my program
is Win32 Application. I tried inpout32.dll but without success. First of
all i could not find any sources of inpout32 library, i
only found inpout32.dll, but when in Project/Properties/Linker/Input/
AdditionalDependencies i add inpout32.dll durring linking i receive:
Linking...
inpout32.dll : fatal error LNK1136: invalid or corrupt file
Results
(when i give incorrect file name path i receive error that non exsting
file - so linker
finds library inpout32.dll but something wrong is with that library).
Does anybody tried that ?
What can i do to get it working ?
I also found UserPort but it's usage was quite complicated for me...
Thanx
Michal Tag: test Tag: 251857
How can I shorten the time of the linking process
Hi!
I created a Dll project using visual c++ 6 (no mfc).
When I'm linking my project (after the compilation step) on "debug
version", (the "Link Incrementally" option is enabled") it take 5-10
seconds. (The size of the output Dll is ~ 8mb ).
When I'm changing the project mode to "Release version", the linking
process becomes very slow ( it takes ~20 minutes!!! and sometimes even
more - size is ~ 3.5 mb ). When I'm enabling the "Link Incrementally"
it returns to take only 5 to 10 seconds...
I tried to anylise the linking process by using "Print Progress
Messages" option, but I didn't understand from it.
I saw it hangs for ~10 minutes before it prints this:
Selected symbol:
"void __cdecl operator delete(void *,void *)" (??3@YAXPAX0@Z)
from One.obj
Replaced symbol(s):
"public: __thiscall ObjCReturn::~ObjCReturn(void)"
(??1ObjCReturn@@QAE@XZ) from Base.obj
"public: __thiscall ObserverA::~ObserverA(void)"
(??1ObserverA@@QAE@XZ) from Orient.lib(ObserverG.obj)
Can someone help me?
How can I shorten the link process on the Release Version?
Thanks,
Maoz Tag: test Tag: 251849
How to convert CStringA which contains embedded NULL chars into a
Hi All,
The variable str was defined as CStringA type, and it contains 57 chars with
embedded NULL chars copied from some memory buffer, now I want to convert it
into a BSTR string using the following statements:
1) int nLen = str.GetLength();
2) int nChars = MultiByteToWideChar(CP_ACP, NULL, str, nLen, NULL, NULL);
3) bstr = SysAllocStringLen(NULL, nChars);
4) MultiByteToWideChar(CP_ACP, NULL, str, nLen, bstr, nChars);
at line#1 I got nLen 57, but at line#2, I got nChars 50, why nChars should
not be 57? Am I doing something wrong?
PS: The str is "50 4b 01 02 14 00 14 00 02 00 08 00 60 8b 16 33 00 00 60 8b
ff ff ff ff 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00
bb b0 fb c2 ee 9d 8f 0e de 04 00 00"
TIA Tag: test Tag: 251843
GetAdaptersAddresses problem
Hello, All!
Why when I call the GetAdaptersAddresses function it does not return any IP
addresses as it should? Because I need both IP address and the connection
name (not adapter name), I have to use the GetAdaptersAddresses function
along with the GetAdaptersInfo function to get all I need.
---
With the best regards, Mahoney. Tag: test Tag: 251839
Problem with threads calling a function
Hi all,
I'm developing a program in C++ (pure API style, no MFC) and seem to have
the following issue with multithreading:
The program is performing extensive calculations which take a long time,
they also can produce messages. On multiprocessormachines, I start several
threads (up to the amount of processors in the system) which work on the
problem in parallel. My problem however comes in when one of the threads
tries to log an event with my own event log (note this has nothing to do with
the windows eventlog).
My eventlog is a simple procedure which just writes some text and a
timestamp into a listview on the main window of the application:
void Log_Event(char* cMessage, int iCat)
{
LVITEM lvi;
SYSTEMTIME st;
int iSize;
TCHAR* cTime;
TCHAR* cDate;
TCHAR* cBuf;
//get the current date and time
GetLocalTime(&st);
//and format it according to the user preferences (works internationally,
even in retro america)
iSize = GetDateFormat(LOCALE_USER_DEFAULT, 0, &st, NULL, NULL, 0);
cDate = (TCHAR *) calloc(iSize, sizeof(TCHAR));
GetDateFormat(LOCALE_USER_DEFAULT, 0, &st, NULL, cDate, iSize);
iSize = GetTimeFormat(LOCALE_USER_DEFAULT, 0, &st, NULL, NULL, 0);
cTime = (TCHAR *) calloc(iSize, sizeof(TCHAR));
GetTimeFormat(LOCALE_USER_DEFAULT, 0, &st, NULL, cTime, iSize);
cBuf = (TCHAR *) calloc(strlen(cDate) + strlen(cTime) + 4, sizeof(TCHAR));
strcat(cBuf, cDate);
strcat(cBuf, " ");
strcat(cBuf, cTime);
lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
lvi.iItem = 0;
lvi.iImage = iCat;
lvi.iSubItem = 0;
lvi.pszText = NULL;
ListView_InsertItem(GetDlgItem(ghWnd, IDC_LV_EVENTLOG), &lvi);
ListView_SetItemText(GetDlgItem(ghWnd, IDC_LV_EVENTLOG), 0, 1, cBuf);
ListView_SetItemText(GetDlgItem(ghWnd, IDC_LV_EVENTLOG), 0, 2, cMessage);
free(cTime);
cTime = 0;
free(cDate);
cDate = 0;
free(cBuf);
cBuf = 0;
}
In order to synchronize access to the Event_Log function, I have a critical
section object. This is how the threads are calling the function:
...
EnterCriticalSection(&csLogEvent);
Log_Event(cBuf, LE_WARNING);
LeaveCriticalSection(&csLogEvent);
...
The problem now appears to be that the Event_Log functions simply hangs on
the line where it does the Listview_InsertItem. That sends all threads to a
grinding halt, even those that are not logging any events. It also stops of
there is only one worker thread, thus precluding any synchronization issues
(in my opinon?).
I should also note that the Event_Log function worked properly before I
implemented the multithreaded option.
I'm really stuck here, any help is greatly appreciated!
Cheers
- Balt Tag: test Tag: 251831
Lexical Parser
Hi,
I am building a lexical parser, But I used recursive file opening like this
main ()
{
ProcessFile(filename);
}
and somewhere in between
ParseFile()
{
GetFileName(&FileName);
// branching statement, So if FileName is necessary to be recursively
opened, the following statement gets executed
ProcessFile (FileName);
}
ProcessFile (char *filename)
{
f = fopen (filename...);
// when in recursion, this returns null
ParseFile();
}
Is this "Cross-edge" Possible?
Thanks
J Tag: test Tag: 251830
How to access the source of a copied object
I want to have a reference to the source object in the receiving object
after a copy (Copy ctr or assignment). I dont want the receiving object
to be able to modify contents in the copied object.
How should i do this?
Here is my first stab at a solution, but its not working.
Its the dynamic downcast from Base* to SubA* that fails when i run. I
want to use a dynamic cast since i sometimes need to do a runtime check
to see if an object is if a certain type. I need to do a downcast to be
able to check the values of the original (source) object.
So how can i have access to the source object, use it as the downcasted
subtype ,and restrict that access to be read-only.
class Base
{
public:
Base() : sourceObj(NULL) {}
virtual ~Base() {}
Base(const Base& other)
{
*this = other
}
Base& operator=(const Base& other)
{
sourceObj = &other;
return *this;
}
protected:
const Base* sourceObj;
}
class SubA : Base
{
public:
SubA() : Base() {}
~SubA() {}
SubA(const SubA& other) : Base(other) {}
int anAttribute;
void checkAttributeOfSource()
{
// Line below casts an error when run in MS VC++ .NET
SubA* a = dynamic_cast<SubA*>(sourceObj);
if (a->anAttribute = 1)
{
// do something
}
}
}
// ---- Main snippet --------
Base* aBase = new SubA();
// Line below casts an error when run in MS VC++ .NET
SubA* aSub = dynamic_cast<SubA*>(aBase);
// --- Scenario B
SubA a1.readFromdatabase();
SubA a2(a1);
a2.ReadFromClient();
// Here i want to be able to query values in a1 without modifying
a1
a2.CompareMeTosourceObject(); Tag: test Tag: 251828
Icon display in Win 2000 and Win XP
Hi,
The taskbar icon of my application is visible in Win XP but not in Win
2000. What could be the various reasons for this?? Tag: test Tag: 251827
How can I use CreateProcess() to get another application`s result??
Hello everyone:
I want to use CreateProcess() call another application, and save the
result in a text file.I can surely exeute the application,but there is
nothing data in the text file.why??
Could you please give me the code example?
Thank you!
//window message process function
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
static STARTUPINFO si;
static PROCESS_INFORMATION pi;
static HANDLE hFile;
static SECURITY_ATTRIBUTES sa;
sa.bInheritHandle = TRUE;
hFile = CreateFile("C:\\Tracert.txt",GENERIC_WRITE,FILE_SHARE_WRITE,
&sa,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
si.dwFlags = STARTF_USESTDHANDLES;
si.hStdOutput = hFile;
switch(msg)
{
case WM_CREATE:
CreateProcess("C:\\WINNT\\System32\\tracert.exe"," www.163.com",
NULL, NULL, FALSE,0, NULL, NULL, &si, &pi);
return 0;
case WM_PAINT:
return 0;
case WM_DESTROY:
CloseHandle(hFile);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,msg,wParam,lParam);
} Tag: test Tag: 251822
Defining template class member functions in a separate module
I have been having link problems (see my previous post) and I got
around to trying one by one, different combinations since I absolutely
could not figure out why things weren't working. I have done exactly
the same type of thing before and it worked like a charm!
I got around to wondering finally if it could be a problem with the way
I have organized things.
Let's assume a template class declaration as follows:
template<typename DeallocType>
class DefaultDeallocator : public virtual Deallocator<DeallocType>
{
public:
DefaultDeallocator();
virtual ~DefaultDeallocator();
virtual void Delete(DeallocType*);
virtual void DeleteObjectArray(DeallocType*);
virtual void DeletePointerArray(DeallocType**, unsigned long);
};
This is in a header called DefaultDeallocator.h (duh! :)
I have the definition in a module called DefaultDeallocator.cpp.
template<typename DeallocType>
DefaultDeallocator<DeallocType>::DefaultDeallocator()
{
}
template<typename DeallocType>
DefaultDeallocator<DeallocType>::~DefaultDeallocator()
{
}
template<typename DeallocType>
void DefaultDeallocator<DeallocType>::Delete(DeallocType* obj)
{
if(NULL != obj)
{
delete obj;
}
}
template<typename DeallocType>
void DefaultDeallocator<DeallocType>
::DeleteObjectArray(DeallocType* array)
{
if(NULL != array)
{
delete[] array;
}
}
template<typename DeallocType>
void DefaultDeallocator<DeallocType>
::DeletePointerArray(DeallocType** ptrarray, unsigned
long num)
{
if(NULL != ptrarray &&
num > 0)
{
for(unsigned long i = 0; i < num; ++i)
{
delete ptrarray[i];
}
}
}
Could it be that because the definition is in a module as opposed to
being completely in the header itself, that I am getting unresolved
external link problems. Here are my errors:
Creating library Debug/SmartPointer2.lib and object
Debug/SmartPointer2.exp
Test.obj : error LNK2019: unresolved external symbol "public: virtual
__thiscall MCMDocumentCache::DefaultDeallocator<class
MCMDocumentCache::ReferenceCounter>::~DefaultDeallocator<class
MCMDocumentCache::ReferenceCounter>(void)"
(??1?$DefaultDeallocator@VReferenceCounter@MCMDocumentCache@@@MCMDocumentCache@@UAE@XZ)
referenced in function "void __cdecl
Test_Deallocator_Construction(void)"
(?Test_Deallocator_Construction@@YAXXZ)
Test.obj : error LNK2019: unresolved external symbol "public:
__thiscall MCMDocumentCache::DefaultDeallocator<class
MCMDocumentCache::ReferenceCounter>::DefaultDeallocator<class
MCMDocumentCache::ReferenceCounter>(void)"
(??0?$DefaultDeallocator@VReferenceCounter@MCMDocumentCache@@@MCMDocumentCache@@QAE@XZ)
referenced in function "void __cdecl
Test_Deallocator_Construction(void)"
(?Test_Deallocator_Construction@@YAXXZ)
Test.obj : error LNK2019: unresolved external symbol "public: virtual
void __thiscall MCMDocumentCache::DefaultDeallocator<class
MCMDocumentCache::ReferenceCounter>::Delete(class
MCMDocumentCache::ReferenceCounter *)"
(?Delete@?$DefaultDeallocator@VReferenceCounter@MCMDocumentCache@@@MCMDocumentCache@@UAEXPAVReferenceCounter@2@@Z)
referenced in function "void __cdecl Test_Deallocator_Delete(void)"
(?Test_Deallocator_Delete@@YAXXZ)
Test.obj : error LNK2019: unresolved external symbol "public: virtual
void __thiscall MCMDocumentCache::DefaultDeallocator<class
MCMDocumentCache::ReferenceCounter>::DeleteObjectArray(class
MCMDocumentCache::ReferenceCounter *)"
(?DeleteObjectArray@?$DefaultDeallocator@VReferenceCounter@MCMDocumentCache@@@MCMDocumentCache@@UAEXPAVReferenceCounter@2@@Z)
referenced in function "void __cdecl
Test_Deallocator_DeleteObjectArray(void)"
(?Test_Deallocator_DeleteObjectArray@@YAXXZ)
Test.obj : error LNK2019: unresolved external symbol "public: virtual
void __thiscall MCMDocumentCache::DefaultDeallocator<class
MCMDocumentCache::ReferenceCounter>::DeletePointerArray(class
MCMDocumentCache::ReferenceCounter * *,unsigned long)"
(?DeletePointerArray@?$DefaultDeallocator@VReferenceCounter@MCMDocumentCache@@@MCMDocumentCache@@UAEXPAPAVReferenceCounter@2@K@Z)
referenced in function "void __cdecl
Test_Deallocator_DeletePointerArray(void)"
(?Test_Deallocator_DeletePointerArray@@YAXXZ)
Debug/SmartPointer2.exe : fatal error LNK1120: 5 unresolved externals
If my supposition is correct, that kind of seems funny. Supposing I
were distributing a library and I didn't want to expose my
implementation, what would I do?
thanks,
-vijai. Tag: test Tag: 251820
Code compiles with VS2003 but not eVC4
Hi,
The following code compiles fine with VS 2003 but not with eVC4 SP4. I am
not sure VS.NET is right since the situation is kind of ambiguous.
Basically, we have a MultiEar class derive "twice" from the same IListener
interface - we do that by aliasing the interface with AListener and
BListener. Two separate vtables should be produced, but... eVC4 does not
seem to think so.
Here is the code:
// interiorListeners.cpp : Defines the entry point for the console
application.
//
/* this test investigates what happens when you need to have multiple
implementations of a base class in a derived class.
Questions:
Is this legal C++?
Is the intent of the syntax clear?
Should it work on all C++ compilers?
*/
#include "stdafx.h"
/** first declare a listener interface */
class IListener
{
public:
virtual void OnEvent(const char * name, int id)=0;
};
/* a class we can listen too */
class EventSource
{
public:
EventSource(const char * name) : m_name(name)
{
m_listener = NULL;
}
void fireEvent(int id)
{
if (m_listener)
m_listener->OnEvent(m_name, id);
}
void addListener(IListener* listener)
{
m_listener = listener;
}
private:
IListener* m_listener;
const char * m_name;
};
/* derived classes used to force the child to have specific
implementations for both versions of listener
*/
class AListener : public IListener
{
// implement IListener
virtual void OnEvent(const char * name, int id)=0;
};
class BListener : public IListener
{
// implement IListener
virtual void OnEvent(const char * name, int id)=0;
};
/* this class wishes to support both listeners with different
implementations
however the implementations need to be in the class scope in order
to access member vars without recourse to parent pointers and the like.
*/
class MultiEar
: public AListener, BListener
{
public:
MultiEar()
: a(_T("EventSource A"))
, b(_T("EventSource B"))
{
m_int = 0;
}
//* This code compiles and works ok on MSVC.NET but not on EVC4.
// implement IListener
void AListener::OnEvent(const char * name, int id)
{
printf(_T("%s %d AListener OnEvent(%s, %d)\n"), ClassName(), m_int,
name, id);
m_int++;
}
// implement IListener
void BListener::OnEvent(const char * name, int id)
{
printf(_T("%s %d BListener OnEvent(%s, %d)\n"), ClassName(), m_int, name,
id);
m_int++;
}
void Test()
{
a.addListener((AListener*)this);
b.addListener((BListener*)this);
a.fireEvent(1);
a.fireEvent(2);
b.fireEvent(1);
b.fireEvent(2);
}
private:
EventSource a, b;
const char * ClassName() { return _T("MultiEar") ; }
int m_int;
};
int _tmain(int argc, _TCHAR* argv[])
{
printf(_T("testing interior listener classes.\n"));
// create the MultiEar
MultiEar multiEar;
multiEar.Test();
return 0;
}
/** expected output
testing interior listener classes.
MultiEar 0 AListener OnEvent(EventSource A, 1)
MultiEar 1 AListener OnEvent(EventSource A, 2)
MultiEar 2 BListener OnEvent(EventSource B, 1)
MultiEar 3 BListener OnEvent(EventSource B, 2)
*/
Any idea?
Thanks! Tag: test Tag: 251818
Continuous KillTimer or SetTimer calls
hi,
am using the SetTimer function and would like to know what happens when
i use two continuous SetTimer calls or KillTimer calls on the same
handle??
eg. i define a timer:
SetTimer with an ID, say ID1.
define it again with the same id, ID1.
According to documentation, this should just reset the timer. Does it
actually do taht?
But what would happen if i try to do the same with KillTimer??
Kill ID1 and then again call KillTimer with ID1.
thanx!! Tag: test Tag: 251811
question about STL on VC6
the following code can not be compiled in VC6 ,but can be compiled in
VC.net2003
Is there any way that make vc6 to support STL better?
#include <iostream>
#include <vector>
using namespace std;
class myc
{
public:
myc():v(5){}
template<class myiter>
void tmpfunc(myiter first,myiter last,int i);
void fun();
private:
vector<int> v;
};
template<class myiter>
void myc::tmpfunc(myiter first,myiter last,int i)
{
for(;first!=last;++first)
{
cout<<*first;
}
cout<<endl;
}
void myc::fun()
{
tmpfunc(v.begin(),v.end(),0);
/*
in vc6 ,there is an error:
G:\myproject\con0002\con002.cpp(30) : error C2893: Failed to specialize
function template 'void __thiscall myc::tmpfunc(myiter,myiter,int)'
With the following template arguments:
'int *'
*/
}
int main()
{
myc m;
m.fun();
return 0;
} Tag: test Tag: 251802
Ending all DLL instances
I have a DLL which has a Hook function. My app loads the initial instance of
the DLL and calls an initialize function to start the hook etc. This hook is
a system wide hook and can attach to all sorts of window (not belonging to
my app). If I end my app, first calling another function to end the hooks,
the other DLL instances are still there. Is there a way to end all instances
of the DLL in one go? Tag: test Tag: 251797
How can I use CreateProcess() to get another application`s result?
Hello everyone:
I want to use CreateProcess() call another application, and save the
result in a text file.I can surely exeute the application,but there is
nothing data in the text file.why??
Could you please give me the code example?
Thank you!
//window message process function
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
static STARTUPINFO si;
static PROCESS_INFORMATION pi;
static HANDLE hFile;
static SECURITY_ATTRIBUTES sa;
sa.bInheritHandle = TRUE;
hFile = CreateFile("C:\\Tracert.txt",GENERIC_WRITE,FILE_SHARE_WRITE,
&sa,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
si.dwFlags = STARTF_USESTDHANDLES;
si.hStdOutput = hFile;
switch(msg)
{
case WM_CREATE:
CreateProcess("C:\\WINNT\\System32\\tracert.exe"," www.163.com",
NULL, NULL, FALSE,0, NULL, NULL, &si, &pi);
return 0;
case WM_PAINT:
return 0;
case WM_DESTROY:
CloseHandle(hFile);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,msg,wParam,lParam);
} Tag: test Tag: 251795
Exporting C++ Classes from a Static Library and from a DLL
I am not sure if this OT, but I will go ahead and post. If it has to be
posted elsewhere let me know.
-vijai.
------
I have a class declared as follows:
#pragma once
// a simple reference counter implementation
#ifndef __REF_COUNTER_H__
#define __REF_COUNTER_H__
#include <iosfwd>
#include "smlibdefs.h"
namespace SMLib
{
class SMLIBAPI_CLASS ReferenceCounter
{
unsigned long m_numrefs;
public:
ReferenceCounter();
ReferenceCounter(const ReferenceCounter&);
ReferenceCounter& operator = (const ReferenceCounter&);
virtual ~ReferenceCounter();
virtual void AcquireReference();
virtual void ReleaseReference();
virtual unsigned long CountReferences() const;
};
};
SMLIBAPI_FUNCTION std::ostream& operator << (std::ostream&, const
SMLib::ReferenceCounter&);
SMLIBAPI_FUNCTION std::wostream& operator << (std::wostream&, const
SMLib::ReferenceCounter&);
#endif
SMLIBAPI_FUNCTION is defined as __declspec(dllimport) or
__declspec(dllexport) depending on whether the class is being imported
or exported. (On Windows. On *nix I don't have to do anything to export
C++ classes I believe. All symbols are exported by default?)
I build a shared library and a static library. I test the class and
it's methods with the following separate test program.
#include <refcounter.h>
#include <windows.h>
#include <iostream>
#include <assert.h>
void Test_ReferenceCounter_Construction()
{
SMLib::ReferenceCounter ctr;
std::wcout<<L"Counter: "<<ctr<<std::endl;
}
void Test_ReferenceCounter_Initialization()
{
SMLib::ReferenceCounter ctr;
std::wcout<<L"Counter: "<<ctr<<std::endl;
assert(ctr.CountReferences() == 0);
}
void Test_ReferenceCounter_CopyConstruction()
{
SMLib::ReferenceCounter ctr;
std::wcout<<L"Counter 1: "<<ctr<<std::endl;
SMLib::ReferenceCounter ctr2 = ctr;
std::wcout<<L"Counter 2: "<<ctr2<<std::endl;
assert(ctr2.CountReferences() == 0);
}
void Test_ReferenceCounter_Assignment()
{
SMLib::ReferenceCounter ctr;
std::wcout<<L"Counter 1: "<<ctr<<std::endl;
ctr.AcquireReference();
ctr.AcquireReference();
SMLib::ReferenceCounter ctr2;
ctr2.AcquireReference();
std::wcout<<L"Counter 2: "<<ctr2<<std::endl;
ctr2 = ctr;
std::wcout<<L"Counter 2 (reassigned): "<<ctr2<<std::endl;
assert(ctr2.CountReferences() == ctr.CountReferences());
}
void Test_ReferenceCounter_ReferenceIncrement()
{
SMLib::ReferenceCounter ctr;
std::wcout<<L"Counter: "<<ctr<<std::endl;
ctr.AcquireReference();
assert(ctr.CountReferences() == 1);
}
void Test_ReferenceCounter_ReferenceDecrement()
{
SMLib::ReferenceCounter ctr;
std::wcout<<L"Counter: "<<ctr<<std::endl;
ctr.AcquireReference();
ctr.AcquireReference();
ctr.ReleaseReference();
assert(ctr.CountReferences() == 1);
}
int main()
{
LoadLibrary("smlib-1.0.0.0");
Test_ReferenceCounter_Construction();
Test_ReferenceCounter_Initialization();
Test_ReferenceCounter_Assignment();
Test_ReferenceCounter_ReferenceIncrement();
Test_ReferenceCounter_ReferenceDecrement();
return 0;
}
However, in the shared library:
I get an unresolved external error only for the overloaded left shift
operator. On the other hand for the static library I get unresolved
external symbols error for all the methods as well as the function. I
use the same makefile to compile both:
executableName = smlib
programName = smlib
version = 1.0.0.0
baseDir = .
incDir = $(baseDir)/
srcDir = $(baseDir)/
!if defined(DEBUG) || defined(_DEBUG)
buildSuffix = d
buildType = DEBUG
!else
buildSuffix =
buildType = RELEASE
!endif
ExtLibs = kernel32.lib \
msvcrt$(buildSuffix).lib \
libc$(buildSuffix).lib \
libcmt$(buildSuffix).lib
Includes = basedefs.h \
smlibdefs.h \
refcounter.h
OutPath = $(MAKEDIR)\$(buildType)
CCOpts = /c /Gd /MDd /EHa /D__SMLIB__BUILD /D$(buildType) /I$(incDir)
CC = cl.exe
LibOpts = /OUT:$(OutPath)\libsmlib-$(version).lib /NOLOGO
/SUBSYSTEM:NATIVE
LIB = lib.exe
LinkOpts = /$(buildType) /DLL /NOLOGO
/OUT:$(OutPath)\smlib-$(version).dll
/IMPLIB:$(OutPath)\smlib-$(version).lib
/PDB:$(OutPath)\smlib-$(version).pdb $(ExtLibs)
LINK = link.exe
refcounter: refcounter.cpp $(Includes)
$(CC) $(CCOpts) /Fo$(OutPath)/refcounter.obj
refcounter.cpp
allObjs = $(OutPath)\refcounter.obj
lib: refcounter
$(LIB) $(LibOpts) $(allObjs)
dll: refcounter
$(LINK) $(LinkOpts) $(allObjs)
all: refcounter dll lib
clean:
del /Q $(OutPath)\*.obj
del /Q $(OutPath)\smlib-$(version).pdb
del /Q $(OutPath)\smlib-$(version).lib
del /Q $(OutPath)\smlib-$(version).exp
del /Q $(OutPath)\smlib-$(version).dll
del /Q $(OutPath)\smlib-$(version).ilk
Anyone have any ideas on what I am doing wrong?
thanks,
-vijai. Tag: test Tag: 251794
Make assign illegal for class
Hi,
Is there any way to explicitly make = or copy construction illegal for a
given class? I have several that are most complex and will at no point ever
need to be copied.
For integrity purposes, is there any way to disable the copy all together
and generate a warning? (I was thinking of having a home made copy
constructor but I have no idea about generating a compile error inside it).
--
- Mark Randall
http://zetech.swehli.com Tag: test Tag: 251782
std::vector<CString> to LPCTSTR *
Hi,
I need to call a function, like dummy_fun( LPCTSTR * ppStr ), the ppStr
parameter's data is stored in a database, so this parameter cannot be
initialized using syntax like LPCTSTR ppStr[] = {_T("AAA"), ..., NULL }.
Following code is used to retrieve data from database and stored them to a
vector and construct the ppStr parameter.
//...
std::vector<CString> vs;
while ( SUCCEEDED(hr) && hr != DB_S_ENDOFROWSET) {
DBSTATUS dt;
rs.GetStatus(_T("ItemText"), &dt);
if (dt == DBSTATUS_S_OK) {
CString str((LPCTSTR)rs.GetValue(_T("ItemText")));
if (!str.IsEmpty()) {
vs.push_back(str);
}
}
hr = rs.MoveNext();
}
LPCTSTR *ppStr = new LPCTSTR[vs.size() + 1];
size_t i = 0, vsMax = vs.size();
while ( i < vsMax) { ppStr[i] = vs[i]; ++i;}
ppStr[vsMax] = NULL; // terminating NULL
dummy_function( ppStr ); // This function has a LPCTSTR * parameter
delete[] ppStr;
//...
Is it the way to do it ?
By the way, it is not a MFC project. I tried to use (LPCTSTR*)&vs[0] also,
but don't know how to put a NULL at the end.
--
peter lin Tag: test Tag: 251780
std::vector<CString> to LPCTSTR *
Hi,
I need to call a function, like dummy_fun( LPCTSTR * ppStr ), the ppStr
parameter's data is stored in a database, so this parameter cannot be
initialized using syntax like LPCTSTR ppStr[] = {_T("AAA"), ..., NULL }.
Following code is used to retrieve data from database and stored them to a
vector and construct the ppStr parameter.
//...
std::vector<CString> vs;
while ( SUCCEEDED(hr) && hr != DB_S_ENDOFROWSET) {
DBSTATUS dt;
rs.GetStatus(_T("ItemText"), &dt);
if (dt == DBSTATUS_S_OK) {
CString str((LPCTSTR)rs.GetValue(_T("ItemText")));
if (!str.IsEmpty()) {
vs.push_back(str);
}
}
hr = rs.MoveNext();
}
LPCTSTR *ppStr = new LPCTSTR[vs.size() + 1];
size_t i = 0, vsMax = vs.size();
while ( i < vsMax) { ppStr[i] = vs[i]; ++i;}
ppStr[vsMax] = NULL; // terminating NULL
dummy_function( ppStr ); // This function has a LPCTSTR * parameter
delete[] ppStr;
//...
Is it the way to do it ?
By the way, it is not a MFC project. I tried to use (LPCTSTR*)&vs[0] also,
but don't know how to put a NULL at the end.
--
peter lin Tag: test Tag: 251779
ListView header re-create problem - TIA
Hi:
Is it possible to re-create (delete/add) column header of a ListView
continuously? Basically I want to switch between different number of column
on the same ListView. I can recreate the header visually (it seems to work)
but when I try to insert the data the new column didn't exist. Any
solution, workaround or suggestion?
Thanks Tag: test Tag: 251773
High Performance TCP Server
I need to develop a high performance TCP server. It constantly serves a huge
amount of transactions. My question is which socket mode shall I use,
blocking or non-blocking ? Thanks. Tag: test Tag: 251772
Is there anyway to forward reference a namespace like STL?
Is there anyway to forward reference a namespace like STL?
I can forward reference a class in my header file like this.
class MyClass;
class AnotherClass
{
MyClass *c;
}
This way I do not need to include the header to MyClass in the header
for AnotherClass.
But how would I do this for something that uses a namespace like STL?
std::vector< Route* > *m_coll; Tag: test Tag: 251764
Pointers To Functions in Classes
I have some code that gives me the following error:
error C2440: '=' : cannot convert from 'char (__thiscall
CFunctionClass::*)(long,long)' to 'char (__cdecl *)(long,long)
'
There is no context in which this conversion is possible
It is obvious that with the difference of calling conventions this won't
work, how do I fix it...
The functions used assigned to the pointer and the function pointer itself
are members of the class CFunctionClass.
Thanks. Tag: test Tag: 251753
Copy constructor !
Hi,
The default copy constructor simply copies each member variable from the
object passed as a parameter to the member variables of the new object. This
is called member -wise (or shallow copy). However if I provide my own copy
constructor but with no code in it, will a shallow copy still be made?
--
Best regards
Robert Tag: test Tag: 251748
DLL and its icon
Hello,
I have "some.DLL" and "some.LIB" developed as "Win32 Dynamic-Link Library".
How can I make them appear in "Windows Explorer" with custom icon ?
I tried to insert "some.ICO" as resource but it doesn't work.
Thank you, dave Tag: test Tag: 251747
returning a formated string
I'm making a function that returns a formated String.
my best attempt is shown but it does not work.
I think it does not expand out the "args" when it is passed in.
is there a way to make CString::Format expand out the Arguments List?
p.s. if I should be using sprintf or something else like that, let me
know also.
my DevEnv is MS VC++ 6
CString GetFormatedString(LPCTSTR fmt,...)
{
va_list args;
CString msg;
va_start(args, fmt);
msg.Format(fmt, args);
va_end(args);
return msg;
}
cheers and thanks Tag: test Tag: 251742
LBUTTONDOWN LBUTTONUP selects text I don't want selected in a textbox
I want to programmatically set the position of a cursor in a textbox
that has focus based on a X and Y value.
However, when I send a WM_RBUTTONDOWN and a WM_RBUTTONUP message to the
textbox it selects the text from where the cursor is to where I want
the cursor to be. All I want is to move the position of the cursor
based on a X and Y values, not select the text.
The code to recreate the issue in C#.
const int WM_LBUTTONDOWN = 0x0201;
const int WM_LBUTTONUP = 0x0202;
textBox1.Focus();
int X = 23;
int Y = 6;
SendMessage(textBox1.Handle, WM_LBUTTONDOWN, Y,X);
SendMessage(textBox1.Handle, WM_LBUTTONUP, Y,X);
Is there another message I can send?
Thanks. Tag: test Tag: 251740
WH_CBT hook problems
I've written a small c++ to inject into a thread using c# as my front
end. It is a very simple problem, to catch whenever a window is opened
within a certain program, but the solution(hook) isn't catching it. The
hook installs fine, returning a true boolean flag, but it doesnt seem
to be raising the CallBack. Any help would be greatly appreciated, here
is some example code, maybe it could help.
C++ DLL - WH_CBT HOOK CLASS
#include "stdafx.h"
#include <windows.h>
#include "CbtHook.h"
HINSTANCE _appInstance;
HookProc CbtHookCallback = NULL;
HHOOK hookCbt = NULL;
static LRESULT CALLBACK InternalCbtHookCallback(int code, WPARAM
wParam, LPARAM lParam);
// DLL main commented out for space, but catches the _appInstance
variable;
// This sets the HookCallback to be used
bool SetCbtHookCallback(HookProc userProc, UINT hookID)
{
if ( userProc == NULL )
return false;
if ( hookID == WH_CBT )
{
if (CbtHookCallback != NULL)
return false;
CbtHookCallback = userProc;
return true;
}
return false;
}
bool InitializeHook(UINT hookID, int threadID)
{
if ( _appInstance == NULL )
return false;
if ( hookID = WH_CBT )
{
if ( CbtHookCallback == NULL )
return false;
hookCbt =
SetWindowsHookEx(hookID,(HOOKPROC)InternalCbtHookCallback,_appInstance,0);
if ( hookCbt != NULL )
return true;
}
return false;
}
// UninitializeHook method commented out for space
// HookCallBack procedure to be caught by my front end c# code
static LRESULT CALLBACK InternalCbtHookCallback(int code, WPARAM
wparam, LPARAM lparam)
{
if ( code < 0 )
return CallNextHookEx(hookCbt, code, wparam, lparam);
//if ( CbtHookCallback != NULL )
CbtHookCallback(code, wparam, lparam);
return CallNextHookEx(hookCbt, code, wparam, lparam);
} Tag: test Tag: 251733
Do I need synchronisation for 1 writer, 1 reader thread?
Hi all,
I have a console C++ app (VC++ 6.0, WIN XP x64) with 1 worker thread created
with _beginthreadex in addition to the main thread of execution (so 2
threads).
The worker thread should carry on until the main thread says stop.
At the moment I have implemented this by having the main thread set a bool
visible to both threads to true (it is initialised to false at startup).
The worker thread simply checks the value of this bool on each iteration of
it's loop and keeps going until it is true. Then, the worker thread cleans
up after itself and returns.
Here is some pseudoish code:
bool stopThread = false;
bool threadStopped = false;
int main (void)
{
createThread();
// do stuff for a while
stopThread = true;
while (threadStopped == false)
{
// wait
};
// do other stuff and exit
}
void thread(void)
{
while (stopThread == false)
{
// do stuff
}
// cleanup
threadStopped = true;
return;
}
As far as I can see this should be fine and perfectly safe (i.e. I do not
need any synchronisation in terms of critical sections, mutexes, semaphores,
events etc..) because each variable is only written by one thread.
Am I right?
Is there a better way with better style etc that isn't overkill?
Many thanks for your time,
Dave Tag: test Tag: 251731
Multi-thread testing platform
What is the best 1-off purchase platform to test multi-threaded code?
Hyperthreaded,
Dual Core
Dual Processor
E.g. most customers using our product on a "multi-processor" platform will
be running a Hyperthreaded processor, a few may be using dual core
processors - most will _not_ have a dual processor setup (except perhaps if
running via a terminal services server).
The way I see it is to get the worst-case-scenario (i.e. a dual processor),
but I need to check first that there are unlikely to be scenarios where an
error would only show itself on Hyperthreaded processor for some reason. (I
guess I'll be varying the background load during testing.)
At the moment, I'm just firing off a second thread to do some DX sound
generation (on-the-fly waveform generation) - beeps and such. Later, I'll
be firing off threads to read and write to the serial port and perhaps other
things too. No high-load server stuff, just the basic one or two worker
threads that may or may not need sychcronisation with the main program.
Thanks. Tag: test Tag: 251728
Which Indentity?
How do I determine which identity is being used when instancing a Windows
system COM component from within a VC++7 COM component?
Regards...Andrew Tag: test Tag: 251725
how to solve "Non-modal forms cannot be displayed in this host application"
Hi,
I am trying to make a modalless form in VB6 that is compiled as an
ActiveX DLL. When i use VC6 to instance the activex DLL, my problem appears
that
"406 Non-modal forms cannot be displayed in this host application from an
ActiveX DLL, ActiveX control or Property Page."
I have my form in modalless style in VB6 and they should be instanced in VC.
Does anyone know how to get this to work ?
Many Thanks,
Xiao Tag: test Tag: 251724
textBox1_TextChanged creates an error
I am using a Visual Studio 2002 and was creating a small C# application that
does very little, but I get the following error trying to build it.
C:\DotNetProjects\DataReaderDemo\Form1.cs(69): 'DataReaderDemo.Form1' does
not contain a definition for 'textBox1_TextChanged'
The code that VS generates is the problem:
private void InitializeComponent()
...
this.textBox1.TextChanged += new
System.EventHandler(this.textBox1_TextChanged);
If I take out the line with textbox1.TextChanged - it works fine.
Why is this an error if VS added it?
Thanks,
Tom Tag: test Tag: 251722
CListBox item's color
Env: VC++6
Is it possible to change CListBox's color by every item while calling
CListBox::AddString()?
William Tag: test Tag: 251721
Dependency generation (CL /E)
Currently with VC6, we invoke the CL compiler with /E, in order to parse the
list of included files, and thus reconstitute our dependency lists.
But with VC7, the compiler introduces absolute paths into the spew (same if
you use /showIncludes). We filter these out, considering the probably
originate from the system path (and we aren't interested in tracking these
dependencies).
* Why does CL do this now? Why has this behavior changed?
* Is it a bug?
* Is there a work-around (regardless of the answers to the other questions)?
Thank you,
Dan Tag: test Tag: 251720
findFirstFile, findNextFike
I need codes to access all files in all subdirectory in one directory in
VC++/VStudio but in console (DOS) mode. Thank you for your help in advance.
M.K. Tag: test Tag: 251718
Setting Title bar size programatically ?
Is it possible to set the height of a title bar on a window programatically ?
Does anyone know how ?
Thanks,
Ray Tag: test Tag: 251709
Fatal error LNK1104: cannot open file "nafxcwd.lib"
I am trying to build an open source VC++ 6 project using VC++ 6 Standard but
I am getting the following error message:
Linking...
LINK : fatal error LNK1104: cannot open file "nafxcwd.lib"
Error executing link.exe.
LeechBlocker.dll - 1 error(s), 1 warning(s)
After searching my drive for nafxcwd.lib, the file was not found and it
appears that this file is not included in the VC++ 6 Std. installation.
Disabling debug gives the same message above indicating a different file
named "nafxcw.lib".
For my project settings, I am using 'Use MFC in a Shared DLL' (all
configurations).
Any comments or suggestions are appreciated. Thank you. Tag: test Tag: 251707
Error calling the function HrESERestoreComplete
Hello All,
I am writing an application to backup and restore M.S. Exchange server
programatically. I am using the Exchange Backup and
Restore API and am developing the application in VC++ 6.0 on a Windows
Server 2003 Enterprise Edition. I am able to do the
backup successfully but I am getting error in the function
"HrESERestoreComplete" during the resore. I am trying to call the
function HrESERestoreComplete as follows:
//<step 8>
//HrESERestoreComplete
CString strTempLocationPath;
CString strTempLocationPath1;
strTempLocationPath = _T("C:\\viraj\\exchangedata_bkp\\temp");
strTempLocationPath1 = _T("C:\\viraj\\exchangedata_bkp\\temp");
WCHAR * wszMNURestoreInstanceSystemPath =
strTempLocationPath.GetBuffer(strTempLocationPath.GetLength());
WCHAR * wszMNURestoreInstanceLogPath =
strTempLocationPath1.GetBuffer(strTempLocationPath1.GetLength());
unsigned long fMNUFlags = ESE_RESTORE_COMPLETE_ATTACH_DBS;
typedef HRESULT (ESEBACK_API *HrESERestoreComplete) (IN HCCX
hccxRestoreContext, IN WCHAR * wszRestoreInstanceSystemPath,
IN WCHAR * wszRestoreInstanceLogPath, IN WCHAR * wszTargetInstanceName, IN
unsigned long fFlags);
HrESERestoreComplete fnMNURestoreComplete = NULL;
fnMNURestoreComplete = (HrESERestoreComplete) GetProcAddress
(g_hESEDll,"HrESERestoreComplete");
if(fnMNURestoreComplete)
hr = (fnMNURestoreComplete)
(phccxMNURestoreContext,wszMNURestoreInstanceSystemPath,
wszMNURestoreInstanceLogPath,wszSrcInstanceName,fMNUFlags);
if(hr != S_OK)
{
LPVOID lpMsgBuf;
DWORD dw = GetLastError();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM, NULL, dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,0,NULL);
CString strMessage = _T("");
strMessage.Format(_T("failed with error %d : %s"),dw,lpMsgBuf);
AfxMessageBox(strMessage);
LocalFree(lpMsgBuf);
return MNU_EXCHANGE_RESTORE_FAILURE;
}
//</step 8>
All the inputs seem to be correct.
Output:
hr = -939585532
dw = 4294965485
Expected Output:
hr = S_OK
Can anyone please point the mistake in my code or give me sample code for
the "HrESERestoreComplete" Function?
Thanks,
Viraj
a.viraj@mobiliti.com
http://www.mobiliti.com
732-248-8300 ext 234 Tag: test Tag: 251705
Modal dialog behavior
When an application displays a modal dialog box, the application's message
pump is blocked until the dialog box is dismissed. How is it then that if
you move that dialog box around, the parent application is redrawn? Are the
WM_PAINT messages in the parent application's message queue still getting
processed, or is something else going on here?
Thanks,
DC Tag: test Tag: 251702
initializing private static array
Hi gang! This is more of a preference issue than a syntax or C++ standards
question. I have a class that has a private static array as a data member.
I know that in the source file for the class, one would normally initialize
all the static data members prior to any operation definitions. However,
with arrays, the compiler thinks that you are redefining the length of the
static array (when specifying a specific index). I can solve this by
"modifying" (as opposed to initializing) the array inside the class
constructor. I know this isn't usually considered "good practice" since
instantiation of each object of the class will execute useless code (the 1st
object will actually modify the data member, all other instantiations will
simply reset the values to what's already stored).
What's the best way to initialize static arrays? Oh, and I understand that
the array will already be initialized to all zero's, but I'd like to
initialize it to something else (it's actually a private static const array).
Thanks as always! Tag: test Tag: 251692
Trade-offs when floating poing consistency?
What are the trade-offs when I disable floating point consisetncy?
I guess my program is still C++ compliant, isn't it?
--
Angel Tsankov
fn42551@fmi.uni-sofia.bg Tag: test Tag: 251688
Is it necessary to have default constructor of a class ??
Hi,
I want to ask a question whether it is a must to have default
constructors (without any parameter) of a class or it will be ok without it
also... I have tried, without default constructor, it is working fine.. but
i heard somewhere that it should be there.. Please tell me what is correct
??
--jigar Tag: test Tag: 251687