|
Halloko wrote:
I thought a DLL was loaded into the .exe memory?
I agree with you, but I would say that its really not a safe way to allocate the memory in .exe and delete in the dll. Simple rule of thumb, the owner of the pointer should delete it.
I have lost more blood shaving than on the battlefield - Adolf Hitler
|
|
|
|
|
Halloko wrote:
Since I know the pointer isn't bad it must be something about a DLL not sharing the .exe's heap.
Is that so? And if yes, why? I thought a DLL was loaded into the .exe memory?
It is about CRT. If you dinamically link to CRT in both dll and exe, than you are OK. Otherwise, you have two instances of CRT loaded in the memory, and you'd better make sure to free the memory with the same instance you allocated it with.
|
|
|
|
|
I do not think it is even possible to load a DLL into an exe address space if the exe is not compiled using dynamic linking.
Kuphryn
|
|
|
|
|
"SystemTimeToTzSpecificLocalTime" Windows Platform SDK call seems to satisy what i want to do. But again to populate the _TIME_ZONE_INFORMATION struct is a problem. Generally it is populated from the local TimeZone (Environment variable). Any Hints/Help to populate this struct with a non-local Timezone data.
BOOL SystemTimeToTzSpecificLocalTime(
LPTIME_ZONE_INFORMATION lpTimeZone,
LPSYSTEMTIME lpUniversalTime,
LPSYSTEMTIME lpLocalTime
);
typedef struct _TIME_ZONE_INFORMATION
{ LONG Bias;
WCHAR StandardName[32];
SYSTEMTIME StandardDate;
LONG StandardBias;
WCHAR DaylightName[32];
SYSTEMTIME DaylightDate;
LONG DaylightBias;
} TIME_ZONE_INFORMATION, *PTIME_ZONE_INFORMATION;
Also i was wondering if anybody has seen the MultiTimeZone Clock Screen Saver. If the source code of that could be got it would make life simpler.
Dimple
|
|
|
|
|
DimpleSurana wrote:
Any Hints/Help to populate this struct with a non-local Timezone data.
I live in GMT-0600, which is known as CST here in the U.S. If I wanted the time for EST, or GMT-0500, I would do something like:
TIME_ZONE_INFORMATION tzi = {0};
SYSTEMTIME stUniversal = {0},
stLocal = {0};
tzi.Bias = 300;
GetSystemTime(&stUniversal);
SystemTimeToTzSpecificLocalTime(&tzi, &stUniversal, &stLocal);
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Hi David,
I really appreciate the code snippets you give me. But i wanted to know that how do i add DST information to it too. For eg. EST timezone see's DST.
I idea is that "stLocal" will be given its TimeZone only once & hence forth onwards it should always know its TimeZone's Time including DST.
Thanks,
Dimple
|
|
|
|
|
Check out the DaylightBias member of the TIME_ZONE_INFORMATION structure.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Do u have ne generic solution that will update the time object based on the incoming timezone.
This is gonna require some manual programming i believe so was loking otu for a code snippet.
Dimple
|
|
|
|
|
Nothing that revolves around a "timezone identifier." Otherwise, the DaylightBias and Bias members should solve your problem.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Hi!
Having problem by using sprintf. I have the hexadecimal 2B67, and will convert it to decimal by using sprintf.
Can someone help me?? I know how to do vice verca.
|
|
|
|
|
As far as i know there is no datatype called hexadecimal.
What is the actuaal data type wheather its Int, long, or string
if its string then you need to convert it to long or int and use the following statemetn
printf("%d",nHexNum);
or
printf("%ld",lHexNum);
Which ever fits rite.
I have lost more blood shaving than on the battlefield - Adolf Hitler
|
|
|
|
|
Mr.Prakash wrote:
As far as i know there is no datatype called hexadecimal.
Then what do you call base-16 numbers?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
humm, is there any data type called base-16 in c/c++????
I have lost more blood shaving than on the battlefield - Adolf Hitler
|
|
|
|
|
No, but there are base-16 numbers, also known as hexadecimal numbers. Referring back to styve's post, he wanted to convert a base-16 number (hexadecimal) to a base-10 number (decimal).
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I certaily agree with you? I was trying to be within the context of C/C++,
Many newbies consider this as hexadecimal no.
int x = 0xff;
I have lost more blood shaving than on the battlefield - Adolf Hitler
|
|
|
|
|
Mr.Prakash wrote:
Many newbies consider this as hexadecimal no.
int x = 0xff;
While 0xff is indeed a hexadecimal number, the variable x is simply a spot in memory.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
What you mean by hexadecimal 2b67 ???
From the machine, it's just the same than 11111 in base-10...
The hexadeciaml is just the way YOU represent the number. But for the machine, it just sees 0's and 1's.
|
|
|
|
|
As I understand you are trying to get hexadecimal equivalent of numeric, as mentioned by others; all data in memory stayed in hexadecimal format, the issue is to display that in hexadecimal acsii char array, take a look below;
DWORD dwTest;
char a[20];
dwTest=0xAABBCCDD;
sprintf(a,"%x",dwText);
AfxMessageBox(a);
|
|
|
|
|
--------------------Configuration: Wyse2 - Win32 Debug--------------------
Here is the only error I get when building my app: Any ideas? I am using VC++ 6.0
Compiling resources...
Compiling...
stdafx.cpp
Wyse160.cpp
Linking...
LINK : fatal error LNK1104: cannot open file "nafxcwd.lib"
Error executing link.exe.
Souce code:
// Wyse160.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "Wyse160.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#undef mc
//#define mc
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
DCB dcb;
int fSuccess;
DWORD dwResult;
DWORD BaudRate;
BYTE ByteSize;
BYTE Parity;
BYTE StopBits;
CString csErrMsg;
CString csTitle;
CString csComm;
char inBuffer[512];
char outBuffer[512];
int Read1COMM(char * inBuffer, DWORD nBytesToRead);
int Write1COMM(char * outBuffer,DWORD nBytesToWrite);
// Fill in the default com port and values for DCB: 9600 bps, 8 data bits, no parity and 2 stop bits
char *pcCommPort = "COM2";
BaudRate = CBR_9600; // set the baud rate
ByteSize = 8; // data size
Parity = NOPARITY; // set parity
StopBits = TWOSTOPBITS; // two stop bits
csTitle.Format("Data Station Wyse Terminal %.2f", version);
SetConsoleTitle(csTitle);
m_hMainWait = CreateEvent( NULL, FALSE, FALSE, NULL);
pcCommPort = "COM1";
BaudRate = CBR_9600;
Parity = NOPARITY;
ByteSize = 8;
StopBits = ONESTOPBIT;
/*Parity = EVENPARITY;
Parity = ODDPARITY;
Parity = NOPARITY;
Parity = MARKPARITY;
StopBits = ONESTOPBIT;
StopBits = ONE5STOPBITS;
StopBits = TWOSTOPBITS; */
csTitle.Format("Data Station Wyse Terminal %.2f %s", version, pcCommPort);
SetConsoleTitle(csTitle);
CommTimeouts = new _COMMTIMEOUTS;
/* m_PKeybrdThread = 0;
m_PScreenThread = 0;*/
m_bLine = false;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
m_hCom = CreateFile (pcCommPort,
GENERIC_READ | GENERIC_WRITE,
0, // open as exclusive access
NULL, // no security
OPEN_EXISTING,
0, // not overlapped I/O
NULL // comm device
);
if (m_hCom == INVALID_HANDLE_VALUE)
{
wyseErr("Connect to COM port failed.");
return (1);
}
// Configure the comm port
fSuccess = GetCommState(m_hCom, &dcb);
if (!fSuccess)
{
// Handle error
wyseErr("Could not get COM state.");
return (2);
}
dcb.BaudRate = BaudRate;
dcb.ByteSize = ByteSize;
dcb.Parity = Parity;
dcb.StopBits = StopBits;
fSuccess = SetCommState(m_hCom, &dcb);
if (!fSuccess)
{
wyseErr("Could not set COM state.");
return (3);
}
CommTimeouts->ReadIntervalTimeout = MAXDWORD;
CommTimeouts->ReadTotalTimeoutConstant = 0;
CommTimeouts->ReadTotalTimeoutMultiplier = 0;
CommTimeouts->WriteTotalTimeoutConstant = 0;
CommTimeouts->WriteTotalTimeoutMultiplier = 0;
fSuccess = SetCommTimeouts(m_hCom, CommTimeouts);
if (!fSuccess)
{
wyseErr("Could not set COM timeouts.");
return (4);
}
fSuccess = GetCommTimeouts(m_hCom, CommTimeouts);
if (!fSuccess)
{
wyseErr("Could not get COM timeouts.");
return (5);
}
printf ("Serial port %s is successfully reconfigured.\n", pcCommPort);
WaitForSingleObject(m_hMainWait, 2000);
Write1COMM(outBuffer,2 /*{# of bytes to write}*/);
Read1COMM(inBuffer,1 /*{# of bytes to read}*/);
_onexit (exitMain);
while (m_bRunning)
{
dwResult = WaitForSingleObject(m_hMainWait, 1000);
}
}
return nRetCode;
/*******************************************************************/
} /* END OF MAIN ROUTINE ********************************************/
/*******************************************************************/
int exitMain ()
{
m_bRunning = false;
return 0;
}
int Read1COMM(char * inBuffer, DWORD nBytesToRead)
{
DWORD nBytesRead = 0;
DWORD dwResult;
int nResult;
m_hCOMMWait = CreateEvent( NULL, FALSE, FALSE, NULL);
while (!nBytesRead)
{
nResult = ReadFile(m_hCom, inBuffer, 1, &nBytesRead , NULL);
if (nBytesRead)
inBuffer[nBytesRead] = 0;
else
dwResult = WaitForSingleObject(m_hCOMMWait, 100);
}
return nBytesRead;
}
int Write1COMM(char * outBuffer,DWORD nBytesToWrite)
{
/* char inBuffer[InBuffSize];*/
DWORD nBytesWritten;
int fSuccess;
nBytesWritten=0;
fSuccess = WriteFile(m_hCom, outBuffer, nBytesToWrite, &nBytesWritten , NULL);
/* m_PKeybrdThread = NULL; */
return fSuccess;
}
|
|
|
|
|
Woah, No need for the code, there is no logic error just linking error that means there is no problem with the code (from compilers view point )
Any way, did you add the nafxcwd.lib entry in the lib in the link tab in project settings.
I have lost more blood shaving than on the battlefield - Adolf Hitler
|
|
|
|
|
|
To get the text of a combobox item I'm currently using the code below:
m_cbCommand.GetLBText (m_cbCommand.GetCurSel (), csItem) I'm just curious as to if this is the best way to be doing this? I didn't really see any other related methods to get the text, but the way I'm using seems clunky. Thanks for any ideas.
- monrobot13
|
|
|
|
|
Nothing wrong in the code. Its perfectly legal.
I have lost more blood shaving than on the battlefield - Adolf Hitler
|
|
|
|
|
monrobot13 wrote:
I'm just curious as to if this is the best way to be doing this?
It's not. Use GetWindowText() instead. Depending on the style of combobox used, GetLBText() will not always get the text in the edit control.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Ah, that's sounds much better. Didn't even think of that. Thanks.
- monrobot13
|
|
|
|