why timer not fired in console application?
Hi, all,
I created one timer in one console application, and this timer associated
with one timer-function. This console application also printed some string
at console screen.
Now the problem is that the timer funcion never fired though the timer was
really created successfully because the timer ID was valid. But if I
created one separate thread and created the timer within this thread, then
all things OK.
Why? We shouldn't create timer in console thread that interacts with user?
Any one could answer me? Thanks.
aling
-- Tag: ansi c compilation Tag: 220610
why timer not fired in console application?
Hi, all,
I created one timer in one console application, and this timer associated
with one timer-function. This console application also printed some string
at console screen.
Now the problem is that the timer funcion never fired though the timer was
really created successfully because the timer ID was valid. But if I
created one separate thread and created the timer within this thread, then
all things OK.
Why? We shouldn't create timer in console thread that interacts with user?
Any one could answer me? Thanks.
aling
-- Tag: ansi c compilation Tag: 220609
How to compile large programs like emacs in /CLR mode?
I want to try to compile emacs using /CLR.
If I have 5 dozen different source code modules does this necessarily
translate to 5 dozen different DLLs? What does 5 dozen different dlls do to
image activation time?
Presently emacs compiles with MSVC6. The makefile first compiles and links a
program called temacs.exe. Then it runs a program called addsection that
edits the executable program to add a new section. Then the newly edited
temacs.exe loads and compiles a b(l)oat load of lisp programs which then
writes the compiled pCode to the section created by program addsection and
then writes a new executable with the compiled lisp code now in the
executable.
Whew! That is amazing! What is even more amazing is also works with the gcc
compile on windows and linux and dozens of other OSes.
So how would you alter the makefile compile with /CLR for Win2K?
Would you rewrite the lisp virtual machine to use the .NET VM and rewrite
the lisp compiler to produce MSIL and save the MSIL in dlls? Uggghhh... Is
there not an easier way? Tag: ansi c compilation Tag: 220604
How to retrieve an executable's build date?
Hello:
I would like to add the date my EXE file was built (i.e. created) to the
About box.
I thought I had it solved with the code snippet at the end of this e-mail,
but I just found out today that it does not work on Windows 98. Namely, the
call to FindFile() returns FALSE;
Any ideas.
TIA.
Michael
CString CMyApp::GetExecutableDateStamp(strWorkingDir)
{
CString strError = "";
CString strFile = "";
CString strMsg;
FileFind fileFind;
strFile.Format("%s\\AB2000.exe", strWorkingDir);
if(!fileFind.FindFile(strFile))
{
strFile.Format("%s\\Release\\MyApp.exe", m_strWorkingDir);
if(!fileFind.FindFile(strFile))
{
strMsg.Format("%s\n\n%s\n\n%s", "Problem getting the date-stamp
for MyApp.",
"Unable to access the file at:", strFile);
AfxMessageBox(strMsg);
return strError;
}
}
CFile appFile(strFile, 0);
CFileStatus status;
VERIFY(appFile.GetStatus(status));
CString strDateStamp;
strDateStamp.Format("%d-%d-%d %02d:%02d",
status.m_mtime.GetMonth(),
status.m_mtime.GetDay(),
status.m_mtime.GetYear(),
status.m_mtime.GetHour(),
status.m_mtime.GetMinute());
return strDateStamp;
} Tag: ansi c compilation Tag: 220598
Could memory corruption cause R6025?
I'm getting intermittent R6025 (pure virtual function call) errors.
I've followed the instructions given by microsoft and added
implementations for all abstract functions and included a DebugBreak()
statement. However, I continue to get the errors. My code makes use of
DX9, but no other libraries. I've checked for memory leaks with a
couple of different tools, but after patching up a few, the problem
remained. So, the question is, what is giving me R6025? My
DebugBreak() statements never get hit and I find it unlikely that my
standard use of the DirectX library would throw these errors. All I
can think of at this point is that it's a memory/stack corruption.
Since it's intermittent, I can't place any breakpoints locate the
problem. I've tried to look for memory corruption using Software
Verify's Memory Validator, but when I try to run it with the tool, my
app crashes. Any ideas? Tag: ansi c compilation Tag: 220590
map fails in destructor
Hi all,
I have a class that looks like:
typedef map<Node*,Node*> NodeMap;
class Component
{
NodeMap inputMap;
NodeMap outputMap;
Node* node;
public:
Component();
~Component()
};
In the destructor I delete node and the rest is done by the compiler. The
funny part is that ~Component() fails with the following stack :
------------------------------------------------------------------------
std::_Tree<std::_Tmap_traits<Node *,Node *,std::less<Node
*>,std::allocator<std::pair<Node * const,Node *> >,0> >::begin() C++
------------------------------------------------------------------------
std::_Tree<std::_Tmap_traits<Node *,Node *,std::less<Node
*>,std::allocator<std::pair<Node * const,Node *> >,0> >::_Tidy() C++
------------------------------------------------------------------------
std::_Tree<std::_Tmap_traits<Node *,Node *,std::less<Node
*>,std::allocator<std::pair<Node * const,Node *> >,0>
>::~_Tree<std::_Tmap_traits<Node *,Node *,std::less<Node
*>,std::allocator<std::pair<Node * const,Node *> >,0> >() C++
------------------------------------------------------------------------
std::map<Node *,Node *,std::less<Node *>,std::allocator<std::pair<Node *
const,Node *> > >::~map<Node *,Node *,std::less<Node
*>,std::allocator<std::pair<Node * const,Node *> > >() C++
------------------------------------------------------------------------
Component::~Component() C++
------------------------------------------------------------------------
and I don't really understand why. All that I do with inputMap and outputMap
are some inserts. However if I switch to STLport I don't see the problem.
Any ideas? I'm thinking memory corruption but not sure....
Nick Tag: ansi c compilation Tag: 220580
Question on _access() ...
Hi,
I want to use _access() to check existence of a file or
dir.
My question is, is _access() able to distinguish a file or
a dir input? For example, if I input "C:\temp\myone", can
_access() tell me if it's a file or dir? How to do it?
I am using it to help me validate a user input, my program
needs to know if the user input is an existing file or
dir.
Thanks,
Peter Tag: ansi c compilation Tag: 220562
InternetReadFile stuffing up downloaded files
When I download the files using InternetReadFile, they seem to lose the
formating all the spaces gets removed, and thus I can't open the file.
Here is the file (it a doc fie)
________
ÑØ?ñ
>
ç?
¬
___________
Using InternetReadFile it makes the file like this..
___________
ÑØ?ñ applied to subsequent systems, and is crucial to a software
organization's business strategy.
The Software A...
_____
it removing so much of the formatting
I am saving the internet files like this
____________-
std::string m_strContents1sdp;
if ( hFile2 )
{
CHAR buffersdp1[1024];
DWORD dwReadsdp1;
while ( InternetReadFile( hFile2, buffersdp1, 1023,
&dwReadsdp1 ) )\
{
if ( dwReadsdp1 == 0 )
break;
buffersdp1[dwReadsdp1] = 0;
m_strContents1sdp += buffersdp1;
}
InternetCloseHandle( hFile2 );
}
//outsdp.open(filename.c_str(), ios::out | ios::binary);
outsdp.open(filename.c_str());
outsdp << m_strContents1sdp << endl;
outsdp.close();
_____________________- Tag: ansi c compilation Tag: 220555
Quiestion on LDAP and CertOpenStore
Hello,
I would like to initialize the store with certificates from the results
of the query specified by a LDAP URL using CertOpenStore with the first
parameter pszStoreProvider set to CERT_STORE_PROV_LDAP. What are the
necessary steps prior to this call ? For example,
how would I specifiy the URL and the port of the LDAP server?. Do I need
initialize the ldap by calling ldap_init ?. How do I need to format the
pvPara parameter?
I have looked at the sample program "Retrieving and Issued Certificate from
the Active Directory" at the microsoft's website and it does not provide me
with enough details.
Thank You! Tag: ansi c compilation Tag: 220551
Execute CreateProcess() with default values
Hi, Friends,
I want to use "CreateProcess()" to open a new file in NotePad.exe with
default strings like
<warehouse>
<store></store>
</warehouse>
How can I achieve that? I tried:
CString cmdargs;
cmdargs = "c:\\winnt\notepad.exe c:\temp\storage.xml
<warehouse><store></store></warehouse>"
Unfortunately, it only opened an empty file.
Any workaround?
Thanks a lot.
Tony Tag: ansi c compilation Tag: 220547
Getting the Active process handle amount
Hi,
How the Amount of handles aquiered by a certain process can be queried? I
didn't find any API that provide this kind of information.... I cant use
'GetProcessHandleCount' as it is only supported on windows XP SP1.
How can I achive the functionality of 'GetProcessHandleCount' on platforms
other then WinXP ???
Thanks,
Nadav. Tag: ansi c compilation Tag: 220542
Save Function to file
hi
is it possible to save a function as binary data to a file ?
ex :
void F(int x)
{
//scope operations only
}
The body of the function would not contain or require any
pointers to outside objects or variables.
The idea would be to override the data of the function , at run time
with the data from a file.
tx Tag: ansi c compilation Tag: 220525
XP styles & themes 2
A shell (context menu) extension in XP displays a dialog. The dialog is
displayed in the old Windows style (not in XP style). I tried to put a
manifest into the shl ext .dll's resource, but it doesn't work.
When I use the MANIFEST_RESOURCE_ID 2 as suggested in the help file, the dll
cannot be loaded. LoadLibrary fails with error 14001.
"This application has failed to start because the application configuration
is incorrect. Reinstalling the application may fix this problem."
what am I doing wrong?
thanks in advance. Tag: ansi c compilation Tag: 220523
multiple word problem
Hello,
I'm writing a program, but I've got a question. I wrote a simple program
that explains my problem. First you must give in an integer and next you
must give a string containing multiple words. If I put an integer in my
variable that is okay, but I have to hit enter twice instead of once for my
string. Is there someone who knows how I can solve this problem ?
Thanks,
Giovanni Noppe,
noppe.g@wanadoo.be
////////////////////////////////////////////////////
#include <string>
#include <iostream>
using namespace std;
void main()
{
int getal;
string zin;
cout<<"Integer : ";
cin>>getal;
cin.ignore(255,'\n');
cin.clear();
cout<<"String : ";
getline(cin,zin);
cout<<"\n\n\n";
cout<<getal<<endl;
cout<<zin;
}
//////////////////////////////////////////////////// Tag: ansi c compilation Tag: 220519
Exporting a Template Function from a DLL
I have a function which I have templatised to work for
different data types :-
template <class T>
void DDX_Text_Units(
CWnd* thisDialog,
CDataExchange* pDX,
CUnitEdit& EditControlVariable,
T& EditBoxNumber,
int nIDC,
int conversionType )...
I want to make these functions available to a large
number of different projects.
Currently this is done by using a DLL, so I have tried
placing the function in the DLL.
I have tried many different ways to export this function
from the DLL, all without success. I tried to follow the
MSDN HOWTO 168958
http://support.microsoft.com/default.aspx?
scid=http://support.microsoft.com:80/support/kb/articles/q
168/9/58.asp&NoWebContent=1
However, I still couldn't get the non-dll code to run the
templatised routine (although the code compiles and runs
OK - it just ignores the routine call).
Here is the code I have tried in the EXPORT.H header :-
//disable warnings on extern before template instantiation
#pragma warning (disable : 4231)
// Provide the storage class specifier (extern for
an .exe file, null
// for DLL) and the __declspec specifier (dllimport
for .an .exe file,
// dllexport for DLL).
// You must define EXP_STL when compiling the DLL.
// You can now use this header file in both the .exe file
and DLL - a
// much safer means of using common declarations than two
different
// header files.
#ifdef EXP_STL
# define DECLSPECIFIER __declspec(dllexport)
# define EXPIMP_TEMPLATE
#else
# define DECLSPECIFIER __declspec(dllimport)
# define EXPIMP_TEMPLATE extern
#endif
// Instantiate template functions DDX_Text_Units<double>
and DDX_Text_Units<float>
// Need to export all template instances EXPLICITELY.
// This code exports them from the DLL and imports them
into the .exe file.
EXPIMP_TEMPLATE template DECLSPECIFIER void DDX_Text_Units
(CWnd*, CDataExchange*, CUnitEdit&, double&, int, int);
Please note, I have tried all sorts of export
declarations, e.g. template<class T>,
DDX_Text_Units<double>, ... etc.
Is it possible to provide several different
DDX_Text_Units routines without having to duplicate code? Tag: ansi c compilation Tag: 220512
Use Automation to control Power Point Viewer 2003 components from Visual C++ application
Hi, I want to control the Power Point Viewer 2003(Viewer not the PPT
Application 2003)components from Visual C++ applications.
It is possible to control the PPT Viewer 97 by using the msppt8.olb file,
but with Power
Point Viewer 2003 the *.olb file doesn't supplied.
Whether it is known any way to solve this problem ?
Thank you. Tag: ansi c compilation Tag: 220507
Window at a given POINT?
If I have a POINT in screen coordinates, can I straightforwardly
find the handle of the top-most window visible at that point?
I was sure there was a way, but can't find it now.
(Even the simple procedure of sending a WM_NCHITTEST to a given
window comes back positive, irrespective of whether there is (say) a
dialogue box hiding that point on the window.)
Dave
--
David Webber
Author MOZART the music processor for Windows -
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mzusers/mailinglist.htm Tag: ansi c compilation Tag: 220505
header file packages (newbie question)
I have written an Ole Db provider... (DLL) and incorporated in this is an
SQLParser (header files and cpp files). However in my Solution directory it
looks very messy. I would like to separate the SQLParser header and cpp
files from the main provider and put them in a sub directory, what is the
best way of doing this?
Thanks,
Duncan Tag: ansi c compilation Tag: 220502
std::ostringstream
I have:
std::ostringstream oss;
as a global variable in my dll and I write bytes in it. The problem is
that when I say:
oss.clear();
it does not clear oss and in next function call it appends bytes, but it
should start loading bytes in oss from the beginning.
How can I clear std::ostringstream?
Thanks. Tag: ansi c compilation Tag: 220499
C++ Refactoring Utility - Beta release available
Hello,
Ref++ is a new C++ refactoring utility. A beta release is now available.
It integrates with Visual Studio 2003 and handles the following refactorings
for standard C++:
- Rename (everything but macros, template elements and namespaces)
- Encapsulate field
- Extract method
- Change method/function signature
- Introduce variable
- Push down class members
- Pull up class members
- Extract superclass
If you are interested in trying out this tool please contact me at
beta@ideat-solutions.com
Regards,
Thierry Miceli Tag: ansi c compilation Tag: 220496
Compiler speed optimisation
I developed code to calculate the inverse of a matrix of
double values.
When I compile my code in release mode with Maximise
Speed optimisation (using Visual Studio DotNet 2003), I
get different answers from when I compile the same code
in debug mode. Initially the values seem to differ at the
15th decimal place, but this causes the one solution to
have an inverse and the other to fail. I was wondering if
somebody else noticed that there is a difference in the
floating point precision when using Maximise Speed
optimisation or not.
Which solution is correct and is there a workaround for
this? Tag: ansi c compilation Tag: 220495
Calling Managed code from Native C++
I know I can use /CLR to create a managed module that can be called by
unmanaged native C++ using COM. Calling COM objects with C++ is not my
favorite past time.
Is there an easier way? Tag: ansi c compilation Tag: 220492
PropertySheetHandler for WebFolder objects?
In Win2K, where in the Registry is the PropertySheetHandler
for Web folder objects?
If I create a new Web folder in My Network Places, and
get the properties for an item, the property sheet is
different than the one for the same object in Explorer.
For instance, if I have a Word document in a local folder
on my machine, I can obtain its properties from Explorer.
There are 4 tabs: General, Security, Custom, and Summary.
Now, I can run IIS on my machine, create a Web folder for
the directory containing the same Word document. Viewing
the Word document there, the properties dialog contains
only one tab, General. That suggests that there's a special
PropertySheetHandler for objects in Web folders, separate
from those for file types. But where?
I want to create a custom property sheet handler for objects
in Web folders.
Any help appreciated. Please followup by email to
steck@stecksoft.com.
-- Paul Tag: ansi c compilation Tag: 220491
Finally solved
To all,
actually, I've left a sentence
"using namespace std;"
I don't know what's the usage of that sentence, but after
adding it, the identifiers such as vector, cout, cin can
all be identified!
Thx! Tag: ansi c compilation Tag: 220489
Problems with exporting C++ in a DLL
I am having a problem trying to move some C++ object code into a DLL. I am
having 2 problems relating to exporting
classes. I am using VC 6 but could use VC 7 if it would help.
The first problem is that I have a object member that is a std::string. The
compiler did not like that, saying that the template
would not be exported. Looking in the MSDN, I found that if you define an
explicit instantiation that has the __declspec(dllexport)
tag attached you can get this to work. However when I tried this for
std::string, the compiler insisted that the type was already
instantiated and ignored the new instantiation. Doing exactly the same thing
for vector<int> worked fine, but not so for std::string.
Does anyone know how to make this work?
The second problem is that one class has two template member functions.
These also do not export even when the class is
declared with __declspec(dllexport). Is there any way to make these members
visible through a DLL?
These worked fine when put into a normal library.
Thanks in advance
Chris Smith
Innovative Integration
csmith@innovative-dsp.com Tag: ansi c compilation Tag: 220487
seg:offset convertion
I'am searching for _DMI_ within the F000:0000 memory and find it, and I
need to convert and address(pointer) within this structure that shows up as:
D48D0F00 to a real address in memory.
The segment shows up as 0F00 and the offset shows up as D48D, I Think that
the address should be F000: 8DD4
Anyone knows the process to do this convertion? Tag: ansi c compilation Tag: 220481
XP style & themes
A shell (context menu) extension in XP displays a dialog. The dialog is
displayed in the old Windows style (not in XP style). I tried to put a
manifest into the shl ext .dll's resource, but it doesn't work. How to make
XP use XP style for shell extension dialogs? Tag: ansi c compilation Tag: 220479
__forceinline and unexpected warning 4714
Hello - I see warning 4714 (can't inline with forceinline) for a case
not listed in the docs. Any insight from this group is most
appreciated.
The entire inline function is one _asm block. When restructured to
use a macro instead of an inline, everything works fine.
I've narrowed the problem to two types of _asm statements, either one
of which causes the dreaded 4714.
Case 1:
_asm lea edx, some_label
Case 2:
_asm jmp edx
I'm not a compiler guy, but I don't see the technical dificulty for
the compiler here, particularly since the _asm block can work as a
macro. The compiler is apparently looking at the _asm statements and
flagging at least these two instructions as an un-inlinable case.
Thanks for any words of wisdom.
-steve Tag: ansi c compilation Tag: 220477
How to free a dialog resource . How to reduce working set size
I'm using DialogBoxIndirect to create a dialog box from a dialog box
template.
Before calling DialogBoxIndirect, I use LoadResource and then LockResource
to get a pointer to a DLGTEMPLATE structure:
HRSRC hRes = ::FindResource(NULL, MAKEINTRESOURCE(id), RT_DIALOG);
m_hGlobal = ::LoadResource(hInstance, hRes);
m_pDlgTemplate = (DLGTEMPLATE*)LockResource(m_hGlobal);
DialogBoxIndirect(...m_pDlgTemplate...);
MSDN says that the system automatically de-allocates the resources when the
application terminates, but I would like to free the resources (allocated by
LoadResource) when my dialog box is closed (application continues to run
after that).
I can't find a suitable function to do that..
FreeResource is obsolete and I can't find a suitable function to release a
RT_DIALOG resource.
2. I would also appreciate if anyone can point me to a good article on
reducing the application's working set size. Although my program's memory
usage isn't big, I'm sure it can be reduced to at least half of what
TaskManager displays.
It seems that mapping a DLL into the process' address space (by calling a
function in, say, mshtml.dll) dramatically increases the working set and I
haven't found a way to unmap the unused DLL's from memory (when I no longer
call functions from that DLL).
Thanks,
Florin Tag: ansi c compilation Tag: 220476
File and Registry monitoring?
I need to have my application monitor when another process (3rd party exe,
source unavailable) either:
a) reads from the registry
or
b) opens a file
In either case, I need to know where (registry key or filepath) that it is
opening.
Any ideas on where to start?
Thanks
--
Adam Clauss
cabadam@tamu.edu Tag: ansi c compilation Tag: 220468
COMBOBOX DIALOGBOX PROBLEM
I have been reading the documentention of msdn
about "combo boxes", well comboboxes are mainly
manipulated with messages and that need the hwnd of it.
That is easy if you create it manually but if you use it
as a resource in a dialog box the thing is not to easy or
i dont know how to handle it.
Can somebody tell me how do i get a handle of a comobox
into a dialogbox or something just to add "an item" to
the comobox in the dialog box?? Tag: ansi c compilation Tag: 220466
File read
I have a program (C) where I am reading the data from
file. For some reason it is not reading the all rows in
file. Is some limitation exists? What should I look for in
order to fix this problem?
while (!feof(stream))
{...} Tag: ansi c compilation Tag: 220457
want to select an item by default in a combo box
Hi, gurus,
I have a combo box in a dialog. Every time I open the dialog, I want to
have an item to be selected by default if a user selected before. How can I
achieve that?
Thanks.
Tony Tag: ansi c compilation Tag: 220455
Reading from mapped drives
The background to this query is that my company runs a
mixed network of XP PC's, and Sun systems which host an
oracle database. The Sun adminstrators arrange to export
certain data to files on the sun, and I require this data
for an XP PC based program run by my users, a program I
have built using developer studio.
From Windows explorer I can create a connection to the
sun directory by using 'map network drive' and specifying
a name like \\sun\data, I can then move into that
directory and see the files on the sun system. I want to
be able to do the same from within my program. My users
may not have a directory already mapped, so I want to
create a mapping/connection that my program can use. I
don't mind if the user cannot see it, and if it vaishes
again when my program terminates (ie. it does not need to
outlive my progam run), but from within my program I want
to find out what files exist (eg: using a CFileFind
object) and then read them (I don't write to the Sun
system).
Can anyone give me some clues, or even a bit or sample
code, that will do this?
many thanks
Peter Jackson Tag: ansi c compilation Tag: 220443
Destructor in Derived Class
I have the following derivations...
class DllExport Wire : public GenModel {...
class DllExport GenModel : public Primitive {...
class DllExport Primitive : public GeoObject, public CObject {...
class DllExport GeoObject : public RefCounted {...
There are other GeoObjects besides Primitives, other Primitives besides
GenModels - well, you get the idea. Wire allocates memory with operator
new. So does GenModel. They all have public destructors.
When the app exits I want to delete any GeoObjects and if a GeoObject is
a GenModel, also delete its allocated data and if it's a Wire, delete
its data too. I make the following call:
GeoObject* pgObj;
...
delete pgObj;
The only destructor called is the GeoObject destructor. None of the
derived class destructors are invoked.
MS Help says: "... derived classes do not inherit their base class's
destructors. Instead, as previously explained, they always override the
base class's destructors." [C++ Language Reference - Using Destructors]
It looks like this time it didn't override the base class' destructor.
How can I coerce the proper (in this example, the Wire) destructor ?
Thanks in advance.
Bill Tag: ansi c compilation Tag: 220429
PSAPI Functions And Services
Hi,
I have a COM object that runs as a service, and launches other COM
objects. Those objects are launched under the Local System account as well,
since the service launches them. For some reason, I cannot see them using
EnumProcesses from the PSAPI dll. Why? How can I work around this?
Thanks. Tag: ansi c compilation Tag: 220425
Get the line of code where leak happened
Hi!
I currently use a libary transported from linux. The auther of this
library use nmake to build the code into a dll and a lib.
And I find there are some leaks in this library. When my MFC
application stop, the vc ide will report a lot of leaks, but there
isn't any information about the line of code which occur the leak.
How can i set the config in the makefile to help IDE position the
source code? In my current config, I can already step into that dll.
Thank you for any suggestion:) Tag: ansi c compilation Tag: 220424
How to use reinterpret_cast?
How can I tell C/C++ compiler to store two bytes into Text[2] instead of
one byte. Word is two bytes, but unsigned char* is one byte. In machine
language, it shows mov byte ptr [], 042. It should be mov word ptr [],
04142. I tried reinterpret_cast, but it does not work. Please advise.
unsigned char* Text = new unsigned char[0x100];
unsigned short Word = 0x4142;
Text[0] = 0x51;
Text[1] = 0x52;
Text[2] = Word;
--
Bryan Parkoff Tag: ansi c compilation Tag: 220421
Dialog Box Windows Messages
Dear all,
Would it be possible to grab some advice on how to parse
Windows messages to dialog boxes created using the
DialogBox method.
At the moment I am trying to locate a method like
FindWindow that returns the HWND to the dialog box.
Best regards,
Jim... Tag: ansi c compilation Tag: 220419
How to create a static library in C, but called by an console AP in CPP.
I create a static library in "C".
Then if I create a console AP with ap.c, the AP can call to the function in
the library.
But if I create a console AP with ap.cpp . The AP can not link to the
library. And the VC++
shows following message.
----------------------------------------------------------------------------
-----------------------------
Compiling...
ap.cpp
Linking...
ap.obj : error LNK2001: unresolved external symbol "int __cdecl
libfunc1(void)" (?libfunc1@@YAHXZ)
Debug/ap.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
ap.exe - 2 error(s), 0 warning(s)
----------------------------------------------------------------------------
--------------------------------------
Both ap.c and ap.cpp are as follows.
extern int libfunc1();
int main()
{
int i;
i=libfunc1();
return i;
}
----------------------------------------------------------------------------
--------------------------------------
Thanks in advance...
Brian Tag: ansi c compilation Tag: 220414
BSTR to CString conversion
How can I convert from BSTR to CString? Something like:
BSTR* b = new bstr[55];
CString str = CString(b);
Thanks. Tag: ansi c compilation Tag: 220411
Problem for winsock, please help~~
Dear all,
I am now writing a winsock project which send and receive data from two
computers. I use a global socket to listen to the port and use 2 winsock
vectors for sending and receiving data. I use the following class structure
to store the data. In the function OnCreate, it will create a thread which
call the function "ClientThread" to select the event by using
WSAEventSelect. When PC1 connect to the PC2, the OnAccept event will be
called in the listener and in the OnAccept function, it will call the accept
and use that socket to receive the data. However, I can't do that because
after executing the OnAccept function, the program will not jump into the
event for the return socket. So the program will stop in the listing
function and wait forever. I want to know how can I solve this problem.
Sorry for my poor English and thank you for all of your help.
class CWinSock
{
public:
enum Role { request, serve } role;
char * buffer, *dataToSend;
int nBytesToSend;
SOCKET s; <-- socket in the class
// Event Function
void OnAccept(...)
void OnSend(...)
void OnReceive(...)
void OnClose(...)
void OnCreate(...) <-- for create the event
}
DWORD WINAPI ClientThread( LPVOID lpParam )
{
CWinSock* vi = (CWinSock*) lpParam;
WSAEVENT hDataEvent = WSA_INVALID_EVENT;
hDataEvent = WSACreateEvent();
HANDLE ev = CreateEvent(0,0,0,0);
int nRet = WSAEventSelect((*vi).s , hDataEvent,
FD_ACCEPT | FD_CLOSE | FD_READ | FD_WRITE );
// Set the event for the socket
if (nRet == SOCKET_ERROR)
{
tcpShowError();
MessageBox(NULL, "Error 1 in listening thread", "Listener Error",
MB_OK);
int reason = WSAGetLastError();
closesocket((*vi).s );
return 1;
}
while (1)
{
int nReturnCode = ::WSAWaitForMultipleEvents(1, &hDataEvent,
FALSE, INFINITE, FALSE);
// Get the listener event
WSANETWORKEVENTS hListenerEvent;
int event = WSAEnumNetworkEvents((*vi).s, hDataEvent,
&hListenerEvent);
if (hListenerEvent.lNetworkEvents == FD_ACCEPT)
{
//Client connect request
(*vi).OnAccept(0);
}
if (hListenerEvent.lNetworkEvents == FD_CLOSE)
{
//Client Close Request
(*vi).OnClose(0);
}
if (hListenerEvent.lNetworkEvents == FD_READ)
{
//Packet Arrive Event
(*vi).OnReceive(0);
}
if (hListenerEvent.lNetworkEvents == FD_WRITE)
{
//Send packet Event
(*vi).OnSend(0);
}
}
WSACloseEvent(ev);
return 0;
}
void CWinSock::OnAccept (int error)
{
CWinSock *socket = new CWinSock(serve);
struct sockaddr_in peerAddress;
int size = sizeof(peerAddress);
socket->s = accept(this->s , (sockaddr*) &peerAddress, &size);
if (socket->s == INVALID_SOCKET)
{
int err = WSAGetLastError();
MessageBox(NULL, "Cannot accept", "Cannot accept", MB_OK);
return;
}
NET_USER_CHECK_DATA check; // Maximum number of users check
int tcpNumberOfUsers ();
extern unsigned char DbmanMaxUser;
check.max_user = DbmanMaxUser ;
check.cur_user = tcpNumberOfUsers ();
socket->OnCreate(0);
int ret = send(socket->s, (char*) &check, sizeof(check), 0);
struct hostent *he = gethostbyaddr ((char*) &peerAddress.sin_addr.S_un,
sizeof(peerAddress), AF_INET);
if(he)
strncpy (socket->peer, he->h_name, sizeof(socket->peer));
else socket->peer[0] = 0;
answerSockets.push_back (socket);
}
Alex Tag: ansi c compilation Tag: 220410
SQLBulkOperations
Hi! I want to insert multi-records at once, and know that the API which
implements funtionality I wish exist.That is SQLBulkOperations().But, It
does not work in testing.The following code is from MSDN.I created table
named "Customers" which have 4 fields, CustID(NUMBER), Name(VARCHAR2(50)),
Address(VARCHAR2(50)), Phone(VARCHAR2(10)) by MS Access.SQLFetchScroll()
works well. But "SQLBulkOperations(hstmt, SQL_ADD);" is failed.So, I call
SQLGetDiagRec() to retrieve error and I get these informations."SQL State :
HY092Native : 87Message : [Microsoft][ODBC Microsoft Access Driver]invalid
feature/option"What is problem? #define UPDATE_ROW 100
#define DELETE_ROW 101
#define ADD_ROW 102
#define SEND_TO_DATA_SOURCE 103
#define UPDATE_OFFSET 10
#define INSERT_OFFSET 20
#define DELETE_OFFSET 30
// Define a structure to hold the customer data. Assume we know the maximum
bookmark
// size to be 10 bytes.
typedef tagCustStruct {
SQLCHAR Bookmark[10];
SQLINTEGER BookmarkLen;
SQLUINTEGER CustID;
SQLINTEGER CustIDInd;
SQLCHAR Name[51];
SQLINTEGER NameLenOrInd;
SQLCHAR Address[51];
SQLINTEGER AddressLenOrInd;
SQLCHAR Phone[11];
SQLINTEGER PhoneLenOrInd;
} CustStruct;
// Allocate 40 of these structures. Elements 0-9 are for the current rowset,
// elements 10-19 are for the buffered updates, elements 20-29 are for
// the buffered inserts, and elements 30-39 are for the buffered deletes.
CustStruct CustArray[40];
SQLUSMALLINT RowStatusArray[10], Action, RowNum, NumUpdates = 0, NumInserts
= 0,
NumDeletes = 0;
SQLINTEGER BindOffset = 0;
SQLRETURN rc;
SQLHSTMT hstmt;
// Set the following statement attributes:
// SQL_ATTR_CURSOR_TYPE: Keyset-driven
// SQL_ATTR_ROW_BIND_TYPE: Row-wise
// SQL_ATTR_ROW_ARRAY_SIZE: 10
// SQL_ATTR_USE_BOOKMARKS: Use variable-length bookmarks
// SQL_ATTR_ROW_STATUS_PTR: Points to RowStatusArray
// SQL_ATTR_ROW_BIND_OFFSET_PTR: Points to BindOffset
SQLSetStmtAttr(hstmt, SQL_ATTR_CURSOR_TYPE, SQL_CURSOR_KEYSET_DRIVEN, 0);
SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_BIND_TYPE, sizeof(CustStruct), 0);
SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_ARRAY_SIZE, 10, 0);
SQLSetStmtAttr(hstmt, SQL_ATTR_USE_BOOKMARKS, SQL_UB_VARIABLE, 0);
SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_STATUS_PTR, RowStatusArray, 0);
SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_BIND_OFFSET_PTR, &BindOffset, 0);
// Bind arrays to the bookmark, CustID, Name, Address, and Phone columns.
SQLBindCol(hstmt, 0, SQL_C_VARBOOKMARK, CustArray[0].Bookmark,
sizeof(CustArray[0].Bookmark), &CustArray[0].BookmarkLen);
SQLBindCol(hstmt, 1, SQL_C_ULONG, &CustArray[0].CustID, 0,
&CustArray[0].CustIDInd);
SQLBindCol(hstmt, 2, SQL_C_CHAR, CustArray[0].Name,
sizeof(CustArray[0].Name),
&CustArray[0].NameLenOrInd);
SQLBindCol(hstmt, 3, SQL_C_CHAR, CustArray[0].Address,
sizeof(CustArray[0].Address),
&CustArray[0].AddressLenOrInd);
SQLBindCol(hstmt, 4, SQL_C_CHAR, CustArray[0].Phone,
sizeof(CustArray[0].Phone),
&CustArray[0].PhoneLenOrInd);
// Execute a statement to retrieve rows from the Customers table.
SQLExecDirect(hstmt, "SELECT CustID, Name, Address, Phone FROM Customers",
SQL_NTS);
// Fetch and display the first 10 rows.
rc = SQLFetchScroll(hstmt, SQL_FETCH_NEXT, 0); //
<------------- Success!DisplayCustData(CustArray, 10);
// Call GetAction to get an action and a row number from the user.
while (GetAction(&Action, &RowNum)) {
switch (Action) {
case SQL_FETCH_NEXT:
case SQL_FETCH_PRIOR:
case SQL_FETCH_FIRST:
case SQL_FETCH_LAST:
case SQL_FETCH_ABSOLUTE:
case SQL_FETCH_RELATIVE:
// Fetch and display the requested data.
SQLFetchScroll(hstmt, Action, RowNum);
DisplayCustData(CustArray, 10);
break;
case UPDATE_ROW:
// Check if we have reached the maximum number of buffered updates.
if (NumUpdates < 10) {
// Get the new customer data and place it in the next available element
of
// the buffered updates section of CustArray, copy the bookmark of the
row
// being updated to the same element, and increment the update counter.
// Checking to see we have not already buffered an update for this
// row not shown.
GetNewCustData(CustArray, UPDATE_OFFSET + NumUpdates);
memcopy(CustArray[UPDATE_OFFSET + NumUpdates].Bookmark,
CustArray[RowNum - 1].Bookmark,
CustArray[RowNum - 1].BookmarkLen);
CustArray[UPDATE_OFFSET + NumUpdates].BookmarkLen =
CustArray[RowNum - 1].BookmarkLen;
NumUpdates++;
} else {
DisplayError("Buffers full. Send buffered changes to the data source.");
}
break;
case DELETE_ROW:
// Check if we have reached the maximum number of buffered deletes.
if (NumDeletes < 10) {
// Copy the bookmark of the row being deleted to the next available
element
// of the buffered deletes section of CustArray and increment the delete
// counter. Checking to see we have not already buffered an update for
// this row not shown.
memcopy(CustArray[DELETE_OFFSET + NumDeletes].Bookmark,
CustArray[RowNum - 1].Bookmark,
CustArray[RowNum - 1].BookmarkLen);
CustArray[DELETE_OFFSET + NumDeletes].BookmarkLen =
CustArray[RowNum - 1].BookmarkLen;
NumDeletes++;
} else {
DisplayError("Buffers full. Send buffered changes to the data source.");
}
break;
case ADD_ROW:
// Check if we have reached the maximum number of buffered inserts.
if (NumInserts < 10) {
// Get the new customer data and place it in the next available element
of
// the buffered inserts section of CustArray and increment the insert
// counter.
GetNewCustData(CustArray, INSERT_OFFSET + NumInserts);
NumInserts++;
} else {
DisplayError("Buffers full. Send buffered changes to the data source.");
}
break;
case SEND_TO_DATA_SOURCE:
// If there are any buffered updates, inserts, or deletes, set the array
size
// to that number, set the binding offset to use the data in the buffered
// update, insert, or delete part of CustArray, and call
SQLBulkOperations to
// do the updates, inserts, or deletes. Because we will never have more
than
// 10 updates, inserts, or deletes, we can use the same row status array.
if (NumUpdates) {
SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_ARRAY_SIZE, NumUpdates, 0);
BindOffset = UPDATE_OFFSET * sizeof(CustStruct);
SQLBulkOperations(hstmt, SQL_UPDATE_BY_BOOKMARK);
NumUpdates = 0;
}
if (NumInserts) {
SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_ARRAY_SIZE, NumInserts, 0);
BindOffset = INSERT_OFFSET * sizeof(CustStruct);
SQLBulkOperations(hstmt, SQL_ADD); // <--------------
Failed!
NumInserts = 0;
}
if (NumDeletes) {
SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_ARRAY_SIZE, NumDeletes, 0);
BindOffset = DELETE_OFFSET * sizeof(CustStruct);
SQLBulkOperations(hstmt, SQL_DELETE_BY_BOOKMARK);
NumDeletes = 0;
}
// If there were any updates, inserts, or deletes, reset the binding
offset
// and array size to their original values.
if (NumUpdates || NumInserts || NumDeletes) {
SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_ARRAY_SIZE, 10, 0);
BindOffset = 0;
}
break;
}
}
// Close the cursor.
SQLFreeStmt(hstmt, SQL_CLOSE); Tag: ansi c compilation Tag: 220409
about __cdecl keyword
It looks to me that use of __cdecl keyword and extern "C" has the same
effect, like in the example:
void __cdecl f1(int i, int j);
extern "C" { void f2(int i, int j); }
f1 and f2 are supposed to have the same calling convention and name
decoration. Is it correct or I'm missing something?
Nikolai Borissov Tag: ansi c compilation Tag: 220406
C++ and persistent objects
Typically C++ persistence implementations, (from the little I've seen),
boils down to something like this:
myclass {
int ivar;
float fvar;
...
saveyourself( file )
{
file.write(ivar);
file.write(fvar);
...
}
};
With this approach we always have to write the code to unwind the variables
to or from the storage media. This can be a big job for objects that involve
complex class hierarchies, and it could impact performance as well.
Another approach is to write/read binary chunks and then use inplace
activation techniques. This is better but what happens when the structure
changes ..., then you need to write conversion functions and you end up
writing code similar to the above where you need to unwind the variables
again.
I'm thinking there must be a better way. After all isn't this exactly what
COM and Corba or XML does to marshal an interface or data structure. With
these frameworks you generally don't have to do the unwinding code yourself
there is typically a tool that does it for you. Is there a way to leverage
these tools to solve the C++ persistence problem, or perhaps there is some
other code available? Am I missing something here?
Any suggestions or links?
Thanks,
Perry. Tag: ansi c compilation Tag: 220405
__int64
Is it possible to use __int64 on Windows NT 4? I didn't
get any compilation error, but seems that it overflows if
the value is bigger than 32-bit. Tag: ansi c compilation Tag: 220404
LoadLibrary assistance needed for debug build of dll
Hello,
I am working with a dll that I would like to load into my application
using LoadLibrary. I have source for the dll, and I have built it as both a
release and a debug version. In my application, the LoadLibrary call fails
if I try to load the debug version of the dll. The call succeeds and I am
able to make subsequent calls to GetProcAddress if I load the release
version of the dll. Why can I not load the debug version of this dll? I'm
currently building the debug version of my application in case that matters
at all.
thanks,
Stuart Tag: ansi c compilation Tag: 220398
How do i get the strictest ansi-compilation on vs 6.0? It should be what
correspends as closely to gcc -wall -pedantic -ansi as possible, thx.
Go to project setting > C++> Language
and disable Microsoft extensions
--
----------
Cheers,
Rajiv Das
-----------
"Michael Nielsen" <no@way.dk> wrote in message news:bphp12$1l2i$1@news.cybercity.dk...
| How do i get the strictest ansi-compilation on vs 6.0? It should be what
| correspends as closely to gcc -wall -pedantic -ansi as possible, thx.
|
| /Michael
|
|
"John L Fjellstad" <john-news@fjellstad.org> skrev i meddelandet
news:om0jpb.lij.ln@192.168.1.1...
> Rajiv Das wrote:
>
> > Go to project setting > C++> Language
> > and disable Microsoft extensions
>
> But then you won't be able to include in MS headers, right?
Right!
Header files windows.h and compadres are pre-ANSI C.
Bo Persson
>
> --
> John L. Fjellstad
>
> A: Top posting!
> Q: What is the most irritating thing on Usenet?