|
how to mix two pcm data?
is there any method in VC++?
or any simple algorithm?
i hav read secondary and primary buffers used for o/p buffer.
but i dont know how to handle them efficiciently.
can anyone help me?
http://www.engineeringproject.net
|
|
|
|
|
very urgent
http://www.engineeringproject.net
|
|
|
|
|
I am writing a template container class similar to a vector or list. I am optimizing the class for performance not size. I want to know between the two examples relatively speaking how much faster example 2 is than 1.
Since the functionality employed within the loops is simple, it stands to reason the conditional testing (in the while clause) is relatively speaking measureable (from a performance standpoint......as compared to a loop where complex assignments are occurring.
Example 1:
T* dst1; //is pointing to legitimate memory address.
T* src1; //is pointing to legitimate memory address.
T* dst2; //is pointing to legitimate memory address.
T* src2; //is pointing to legitimate memory address.
T* stop = dst1 - 1000000; //is pointing to legitimate memory address as part of the same array dst points to.
while (dst1-- > stop){
*dst1 = *--src1;
}
stop = dst2 - 1000000;
while (dptr2-- > stop){
*dst2= *--src2;
}
Example 2:
T* dst1; //is pointing to legitimate memory address.
T* src1; //is pointing to legitimate memory address.
T* dst2; //is pointing to legitimate memory address.
T* src2; //is pointing to legitimate memory address.
T* stop = dst1 - 1000000; //is pointing to legitimate memory address as part of the same array dst points to.
while (dst1-- > stop){
*dst1= *--src1;
*--dst2= *--src2;
}
Obviously 2 is faster, but by how much?? In other words compared to the increment operations dereferencing and assigning of memory addresses, how much does the 1000000 conditional tests affect performance compared to the 1000000 of each operations occurring in the loop.
Thanks
|
|
|
|
|
Without knowing the microprocessor architecture + compiler optimization specifics, it's hard to give a "how much" answer.
Working off a super-simplified instruction set, the first example can be generalized to the following. We'll assume that the architecture has branch prediction and that compiler optimization has rearranged the memory accesses so they effectively take just one spot in the pipeline.
loop 1
x1 million:
decrement dst1
compare/branch dst1 to stop
decrement src1
read memory at src1
write memory at dst1
loop 2
x1 million:
decrement dst2
compare/branch dst2 to stop
decrement src2
read memory at src2
write memory at dst2
Second example
loop
x1 million:
decrement dst1
compare/branch dst1 to stop
decrement src1
read memory at src1
write mem at dst1
decrement src2
decrement dst2
read mem at src2
write mem at dst2
With this oversimplification, the second example will run at 9/10 the time of the first.
If the memory accesses are the limiting factor in performance, then the difference between the examples will be negligible. Also, depending on the size of the data and the amount of physical memory available to your process, the first one example might possibly run faster since it better obeys the principle of spatial locality.
If branching policy is the limiting factor, then the second example would perform even better (as in less time) than 9/10 the time of the first, since it has 1 million less branch instructions.
Best way to check is to implement both and time a few typical data runs through both.
FTS Technology Solutions
|
|
|
|
|
Hi,
I'm trying to overlay opengl onto a mfc bitmap. However, im getting the bitmap appearing for one frame before being replaced by the gl, even when i dont use glClear().
Im trying using both StretchDIBits() and a vfm windowless webcam stream, and work up until the opengl is applied, when i get the flickering.
This is the current proccess:
get bitmap / stream
glClear
draw bitmap using StretchDIBits()
draw gl scene
swapbuffers
It seems as if its an issue with the mfc bitmap automatically swapping buffers (i need to use double buffering at least) before the gl is drawn. Ive tried every combination of the above, and still cant get my head around it! If anyone has any ideas, id greatly appreciate it.
Thanks in advance,
Adam Vanner
-- modified at 12:49 Saturday 22nd July, 2006
|
|
|
|
|
im having tremendous difficulty in trying to alter some code. I need what is basically a console chat application between a client and a server implemented using a named pipe. I'm not going to re-list code which is found a hundred times already on this site although none of them seem to do specifically what im asking for. Can anyone help?...please!!!
If i'm not dead enough for life, am i alive enough for death?
|
|
|
|
|
eeyor666 wrote: Can anyone help?...please!!!
which code are you using!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
the following is all .cpp and all .h files i have used.
<pre>//*******************************************************************************************
// CLIENTNP.CPP
/* client/server program CLIENT
clientNP connection-oriented client*/
/* execute a command line(on the server);display the response
client creates a long-lived connection with the server(consuming a pipe instance)
and prompts user for a command*/
#include "EvryThng.h"
#include "ClntSrvr.h" //defines the request, records
int _tmain(int argc,LPTSTR argv[])
{
HANDLE hNamedPipe = INVALID_HANDLE_VALUE;
TCHAR PromptMsg[] = _T("\nEnter Command: ");
TCHAR QuitMsg[] = _T("$Quit");
TCHAR ServerPipeName[MAX_PATH];
REQUEST Request; //see ClntSrvr.h
RESPONSE Response; //see ClntSrvr.h
DWORD nRead, nWrite, NpMode = PIPE_READMODE_MESSAGE | PIPE_WAIT;
LocateServer (ServerPipeName);
//wait for an NP instance and "race" to open it.
while (INVALID_HANDLE_VALUE == hNamedPipe{
WaitNamedPipe (SeverPipeName, NMPWAIT_WAIT_FOREVER);
hNamedPipe = CreateFile (ServerPipeName,
GENERIC_READ | GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, FILE ATTRIBUTE_NORMAL, NULL);
}
//SET NP HANDLE TO BLOCKING, message mode
SetNamedPipeHandleState(hNamedPipe, &NpMode, NULL, NULL);
//prompt user for commands. Terminate on "$QUIT."
while (ConsolePrompt (PromptMsg, Request.Record,
MAX_RQRS_LEN, TRUE)
&&(_tcsmcmp (Request.Record, QuitMsg) !=0)){
WriteFile (hNamedPipe, &Request, RQ_SIZE &nWrite, NULL);
//read each response and send it to std out
//Response.Status == 0 indicates "end of response."
while (ReadFile (hNamedPipe, &Response, RS_SIZE,
&nRead, NULL)&&(Response.Status == 0))
_tprintf(_T("%s"),Response.Record);
}
_tprintf(_T("Quit command recieved. Disconnect."));
CloseHandle(hNamedPipe);
return 0;</code>
}
//*********************************************************************************************************
// SERVERNP.CPP
/* multithreaded command line server. Named pipe version*/
#include "EvryThng.h"
#include "ClntSrvr.h" /* Request and response message definitions*/
typedef struct{ /* argument to a server thread. */
HANDLE hNamedPipe; /* Named Pipe Instance */
DWORD ThreadNo;
TCHAR TmpFileName [MAX_PATH]; /* Temporary file name */
} THREAD_ARG;
typedef THREAD_ARG *LPTHREAD_ARG;
volatile static BOOL ShutDown = FALSE;
static DWORD WINAPI Server (LPTHREAD_ARG);
static DWORD WINAPI Connect (LPTHREAD_ARG);
static DWORD WINAPI ServerBroadcast (LPLONG);
static BOOL WINAPI Handler (DWORD);
static TCHAR ShutRqst [] = _T ("$ShutDownServer");
_tmain (int argc,LPTSTR argv []);
{
/* MAX_CLIENTS is defined in ClntSrvr.h */
HANDLE hNp, hMonitor, hSrvrThread [MAX_CLIENTS];
DWORD iNp, MonitorId, ThreadId;
LPSECURITY_ATTRIBUTES pNPSA = NULL;
THREAD_ARG ThArgs [MAX_CLIENTS];
/* Console control handler to permit server shutdown */
SetConsoleCtrlHandler (Handler, TRUE);
/* Create a thread broadcast pipe name periodically */
hMonitor = (HANDLE) _beginthreadex (NULL,
0,
ServerBroadcast,
NULL,
0,
&MonitorId);
/* Create pipe instance & temp file for every server thread. */
for (iNp = 0; iNp < MAX_CLIENTS; InP++){
hNp = CreateNamedPipe (SERVER_PIPE,
PIPE_ACCESS_DUPLEX,
PIPE_READMODE_MESSAGE | PIPE_TYPE_MESSAGE | PIPE_WAIT,
MAX_CLIENTS,
0,
0,
INFINITE,
pNPSA);
ThArgs [iNp].hNamedPipe = hNp;
ThArgs [iNp].ThreadNo = iNp;
GetTempFileName (_T("."),_T("CLP"),0,ThArgs [iNp].TmpFileName);
hSrvrThread [iNp] = (HANDLE)_beginthreadex (NULL, 0, Server, &ThArgs [iNp], 0, &ThreadId);
}
/* Wait for all threads to terminate */
WaitForMultipleObjects (MAX_CLIENTS,
hSrvrThread,
TRUE,
INFINITE);
WaitForSingleObject (hMonitor, INFINITE);
CloseHandle (hMonitor);
for iNp = 0; iNp<MAX_CLIENTS; iNp++){
/* Close pipe handles and delete temp files. */
CloseHandle(hSrvrThread [iNp]);
DeleteFile (ThArgs [iNp].TmpFileName);
}
_tprintf (_T("Server Process has shut down.\n"));
}
//***********************************************************************************
static DWORD WINAPI Server (LPTHREAD_ARG pThArg)
/* Server thread function; one for every potential client. */
{
HANDLE hNamedPipe, hTmpFile = INVALID_HANDLE_VALUE,
hConTh, hClient;
DWORD nXfer, ConThId, ConThStatus;
STARTUPINFO StartInfoCh;
SECURITY_ATTRIBUTES TempSA =
{sizeof (SECURITY_ATTRIBUTES), NULL, TRUE};
PROCESS_INFORMATION ProcInfo;
FILE *fp;
REQUEST Request;
RESONSE Response;
GetStartupInfo (&StartInfoCh);
hNamedPipe = pThArg->hNamedPipe;
hTmpFile = CreateFile (pThArg->TmpFileName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
&TempSA,
CREATE_ALWAYS,
FILE_ATTRIBUTE_TEMPORARY,
NULL);
while (!ShutDown){ /* Connection Loop */
/* Create connection thread; wait for it to terminate */
hConTh = (HANDLE)_beginthreadex (NULL,
0,
Connect,
pThArg,
0,
&ConThId);
/* Wait for a client connection & test shutdown flag */
while(!ShutDown && WaitForSingleObject (hConTh, CS_TIMEOUT)==WAIT_TIMEOUT)
{/* EMPTY LOOP BODY */};
if (ShutDown) continue; /*Flag can be set by any thread */
CloseHandle (hConTh);
/* A CONNECTION NOW EXISTS */
While (!ShutDown && ReadFile
hNamedPipe, &Request, RQ_SIZE, &nXfer, NULL)/*should there be another bracket here?*/{
/* Recieve new commands until the client disconnects */
ShutDown = ShutDown ||
(_tcscmp (Request.Record, ShutRqst)==0);
if (ShutDown) continue; /* Tested on each iteration*/
/*Create a process to carry out the command*/
StartInfoCh.hStdOutput = hTmpFile;
StartInfoCh.hStdError = hTmpFile;
StartInfoCh.hStdInput = GetStdHandle (STD_INPUT_HANDLE);
StartInfoCh.dwFlags = STARTF_USESTDHANDLES;
CreateProcess (NULL,
Request.Record,
NULL,
NULL,
TRUE, /*INHERIT HANDLES*/
0,
NULL,
NULL,
&StartInfoCh,
&ProcInfo);
/* Server Process Is Running */
CloseHandle(ProcInfo.hThread);
WaitForSingleObject(ProcInfo.hProcess, INFINITE);
CloseHandle(ProcInfo.hProcess);
/* Respond line at a time. It is convenient to use C
Library line-oriented routines at this point */
fp= _tfopen(pThArg->TmpFileName, _T("r"));
Response.Status = 0;
while (_fgetts(Response.Record, MAX_RQRS_LEN, fp!=NULL)
WriteFile (hNamedPipe,
&Response,
RS_SIZE,
&nXer,
NULL);
FlushFileBuffers (hNamedPipe);
fclose(fp);
/* erase temp file contents */
SetFilePointer (hTmpFile,
0,
NULL,
FILE_BEGIN);
SetEndOfFile(hTmpFile);
/* Send an end of response indicator. */
Response.Status = 1; strcpy(Response.Record, "");
WriteFile (hNamedPipe,
&Response,
RS_SIZE,
&nXfer,
NULL);
}
/* end of main command loop. Get next command */
/* Shut down active connection thread */
GetExitCodeThread (hConTh, &ConThStatus);
if (ConThStatus == STILL_ACTIVE){
hClient = CreateFile(SERVER_PIPE,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hClient != INVALID_HANDLE_VALUE)
CloseHandle (hClient);
WaitForSingleObject (hConTh, INFINITE);
}
/* Client disconnected or there is a shutdown request */
FlushFileBuffers (hNamedPipe);
DisconnectNamedPipe (hNamedPipe);
}
/* end of command loop. Free resources; exit from the thread */
if (hTmpFile != INVALID_HANDLE_VALUE)
CloseHandle (hTmpFile);
DeleteFile (pThArg->TmpFileName);
_tprintf(_T("Exiting thread number %d\n"), pThArg->ThreadNo);
_endthreadex(0);
}
static DWORD WINAPI Connect (LPTHREAD_ARG pThArg)
{
/* connection thread allowing server to poll shutdown flag */
ConnectNamedPipe(pThArg->hNamedPipe, NULL);
_endthreadex(0);
return 0;
}
BOOL WINAPI Handler (DWORD CtrlEvent)
{
/* shut down the system */
ShutDown = TRUE;
return TRUE;
}
//***************************************************************************************************
// EvryThng.h
/* EvryThng.h -- all standard and custom include files*/
#include "Exclude.h" /* excludes definitions not required by the sample program*/
#include "envirmnt.h"
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <io.h>
#include "support.h"
#ifdef _MT
#include <process.h>
/* DWORD_PTR (pointer precission unsigned integer) is used for integers
* that are converted to handles or pointers.
* This eliminates Win64 warnings regarding conversion between
* 32-bit and 64-bit data, as HANDLEs and pointers are 64 bits in
* Win64. This is enabled only if _Wp64 is defined
*/
#if !defined(_Wp64)
#define DWORD_PTR DWORD
#define LONG_PTR LONG
#define INT_PTR INT
#endif
******************************************************************************************
//ClntSrvr.h
/* Definitions for Client/Server communication
* request and response messages. Messages are in ASCII as
* the request may be coming from a Windows 95 system.*/
#define MAX_RQRS_LEN 0x1000
typedef struct{
DWORD32 RqLen; //request length, not including this field
CHAR Command;
BYTE Record[MAX_RQRS_LEN];
}REQUEST;
typedef struct{
DWORD32 RsLen //repsonse length, not including this field
CHAR Status;
BYTE Record[MAX_RQRS_LEN];
}RESPONSE;
#define RQ_SIZE sizeof (REQUEST)
#define RQ_HEADER_LEN RQ_SIZE-MAX_RQRS_LEN
#define RS_SIZE sizeof (RESPONSE)
#define RS_HEADER_LEN RS_SIZE-MAX_RQRS_LEN
//mailslot message structure
typedef struct{
DWORD msStatus;
DWORD msUtilization;
TCHAR msName[MAX_PATH];
}
#define MSM_SIZE sizeof (MS_MESSAGE)
#define CS_TIMEOUT 5000 //timeout period for named pipe
//connections and perfomrnance monitoring
#define MAX_CLIENTS 10
#define MAX_SERVER_TH 4 //max num of server threads for serverNPCP
#define MAX_CLIENTS_CP 16 //max num of clients for serverNPCP
//client and server pipe & mailslot names
#define SERVER_PIPE _T("\\\\.\\PIPE\\SERVER")
#define CLIENT_PIPE _T("\\\\.\\PIPE\\SERVER")
#define SERVER_BROADCAST _T ("SrvrBcst.exe")
#define MS_SRVNAME _T("\\\\.\\MAILSLOT\\CLS_MAILSLOT")
#define MS_CLTNAME _T("\\\\.\\MAILSLOT\\CLS_MAILSLOT")
#define MX_NAME _T ("ClientServerMutex")
#define SM_NAME _T ("ClientServerSemaphore")
//commands for the statistics maintenance function
#define CS_INIT 1
#define CS_RQSTART 2
#define CS_RQCOMPLETE 3
#define CS_REPORT 4
#define CS_TERMTHD 5
//client/server support functions
BOOL LocateServer (LPTSTR);
//******************************************************************************************
//Exclude.h
// Exclude.h -- define variables to exclude selected header files.
#define WIN32_LEAN_AND_MEAN //this has the largest impact,
//halving the precompiled header(phc) file size
//the following definitions all reduce the phc and improve compiling time
#define NOATOM
#define NOCLIPBOARD
#define NOCOMM
#define NOCTLMGR
#define NOCOLOR
#define NODEFERWINDOWPOS
#define NODESKTOP
#define NODRAWTEXT
#define NOEXTAPI
#define NOGDICAPMASKS
#define NOHELP
#define NOICONS
#define NOTIME
#define NOIMM
#define NOKANJI
#define NOKERNEL
#define NOKEYSTATES
#define NOMCX
#define NOMEMMGR
#define NOMENUS
#define NOMETAFILE
#define NOMSG
#define NONCMESSAGES
#define NOPROFILER
#define NORASTEROPS
#define NORESOURCE
#define NOSCROLL
#define NOSERVICE
#define NOSHOWWINDOW
#define NOSOUND
#define NOSYSCOMMANDS
#define NOSYSMETRICS
#define NOSYSPARAMS
#define NOTEXTMETRIC
#define NOVIRTUALKEYCODES
#define NOWH
#define NOWWINDOWSTATION
#define NOWINMESSAGES
#define NOWINOFFSETS
#define NOWINSTYLES
#define OEMRESOURCE
//*****************************************************************************************
//Support.h
/* Support -- definitions of all symbolic constants and common utility functions
* IT IS BEST TO DEFINE UTILITY_EXPORTS AND STATICLIB WITHIN THE
* PROJECT RATHER THAN HERE.
* The name UTILITY_EXPORTS is generated by Dev Studio when you create
* a DLL project named "Utility" and it is defined on the C command line
*/
//UTILITY_3_0_EXPORTS is defined within the UTILITY_3_0 project
#if defined(UTILITY_3_0_EXPORTS)
#define LIBSPEC _declspec(dllexport)
#elif defined(__cplusplus)
#define LIBSPEC extern "C" _declspec (dllimport)
#else
#define LIBSPEC _declspec (dllimport)
#endif
#define EMPTY _T ("")
#define YES _T ("y")
#define NO _T ("n")
#define CR 0x0D
#define LF 0x0A
#define TSIZE sizeof (TCHAR)
//limits and constants
#define TYPE_FILE 1 //used in ls, rm and lsFP
#define TYPE_DIR 2
#define TYPE_DOT 3
#define MAX_OPTIONS 20 //max # of command line options
#define MAX_ARG 1000 //max # of command line arguments
#define MAX_COMMAND_LINE MAX_PATH+50 //max size of a command line
//commonly used functions
LIBSPEC BOOL ConsolePrompt (LPCTSTR, LPTSTR, DWORD, BOOL);
LIBSPEC BOOL PrintStrings (HANDLE, ...);
LIBSPEC BOOL PrintMsg(HANDLE, LPCTSTR);
LIBSPEC VOID ReportError (LPCTSTR, DWORD, BOOL);
LIBSPEC VOID ReportException (LPCTSTR, DWORD);
LIBSPEC DWORD Options (int, LPCTSTR *,LPCTSTR, ...);
LIBSPEC LPTSTR SkipArg (LPCTSTR);
LIBSPEC VOID GetArgs (LPCTSTR, int *, LPTSTR *);
// collection of generic string functions modeled after string.h
// created as required
LIBSPEC LPCTSTR whemchr (LPCTSTR, TCHAR, DWORD);
#ifdef _UNICODE //this declaration has to be added
#define _tstrrchr wcsrchr
#else
#define _tstrrchr strrchr
#endif
#ifdef _UNICODE //this declaration has to be added
#define _memtchr wmechr
#else
#define _memtchr memchr
#endif
//security functions
LPSECURITY_ATTRIBUTES InitializeUnicSA (DWORD, LPTSTR, LPTSTR, LPDWORD, LPHANDLE);
LPSECURITY_ATTRIBUTES InitializeAccessOnlySA (DWORD, LPTSTR, LPTSTR, LPWORD, LPHANDLE);
DWORD ReadFilePermissions (LPTSTR, LPTSTR, LPTSTR);
BOOL ChangeFilePermissions (DWORD, LPTSTR, LPTSTR, LPDWORD);
//constants needed by the security functions
#define LUSIZE 1024
#define ACCT_NAME_SIZE LUSIZE
//**************************************************************************************************
///* Envirmnt.h -- define UNICODE and _MT here
* It is best and easiest to define UNICODE within the project
* use Project...Settings...C/C++. Then, in the "Project Options"
* window on the bottom, add /D "UNICODE".
* Do the same for _MT and _STATIC_LIB.
*/
//#define UNICODE
#undef UNICODE
#ifdef UNICODE
#define _UNICODE
#endif
#ifdef UNICODE
#undef _UNICODE
#endif
//#define _STATICLIB
/* define _STATICLIB if you are either building a
* static library or linking with one*/
#define LANG_DFLT LANG_ENGLISH
#define SUBLANG_DFLT SUBLANG_ENGLISH_US</pre>
*****************************************************************************************
let me know what you can do with this as i have got into a right mess so far (as you can probably tell!!!
If i'm not dead enough for life, am i alive enough for death?
|
|
|
|
|
The following function takes in TreeNode *& root as one parameter given the fact that there is struct caled TreeNode.
TreeNode *root = NULL;
void treeInsert( TreeNode *& root, string newItem) {
if ( root == NULL ) {
root = new TreeNode(newItem);
return;
}
else if ( newItem < root->item ) {
treeInsert( root->left, newItem );
}
else {
treeInsert( root->right, newItem );
}
}
but, if I change the parameter to TreeNode & root, obviously this function loses value pointed by root pointer. Why is it this way? because when I have a function like below, even after existing the function, I still have head pointing to some value. (even without *& sign before head parameter)
Node * head = NULL;
void buildNode( Node * head, int valTemp)
{
if ( head == NULL)
{
Node * temp = new Node;
temp->next = NULL;
temp->val = valTemp;
head = temp;
}
else
{
Node *temp = head;
if( temp->next == NULL)
{
temp->next = new Node;
temp->next->val = valTemp;
temp->next->next = NULL;
}
else
{
while( temp->next!= NULL)
{
temp = temp->next;
}
temp->next = new Node;
temp->next->val = valTemp;
temp->next->next = NULL;
}
}
}
-- modified at 9:58 Saturday 22nd July, 2006
|
|
|
|
|
I want to change the bitmap of my toolbar button during runtime
i.e initially the bitmap is x on pressing it should change to y bitmap
how do i do that
please help me out
i am unable to find the right solution
Thanks in advance
|
|
|
|
|
|
I would like to test a library (dll) created with Visual C++. I have copied the .lib file to the project directory and created a button 'Test'.
How / do I use the extern function to be able to create objects of the classes created within the .lib file?
This example is not correct I know, but CSentenceAr is the Name of the class within the dll:
as in ... extern "C" _declspec(dllimport) CSentenceAr;
Is it possible to use the .dll file instead?
Jon
|
|
|
|
|
Do you have (header).h files associated with the .lib and .dll files?
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
I dont know why the hell the script for voting 5 is disabled only for me??
|
|
|
|
|
If you wanna go by the .h + .lib way it's called implicit linking. Where you don't need to specify the location of the dll and call explicitly. You can call the functions as if their implementation is available in another file in you project.
You can use the DLL in another way. Explicit linking., where you will need these two
LoadLibrary^ This is to load the dll.\
GetProcAddress^This to locate a specific function inside the dll.
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
I dont know why the hell the script for voting 5 is disabled only for me??
|
|
|
|
|
And in the end FreeLibrary
|
|
|
|
|
Hello,
We have an MFC application developed on Visual Studio .NET.
When we run it on PC's who have the VS installed, we have no problems. If, however, we attempt to run it on a PC without a Visual Studio installed on it, the application crashes as soon as we attempt to open a certain dialog.
The crash message indicates the error originates in the file occmgr.cpp, line 410 - an assert on the success of new COleControlSiteOrWnd.
I tried checking all OLE* dll's are present, as well as install .net framework 1.1 and 2.0, to no avail.
Any help would be greatly appreciated.
Eran.
|
|
|
|
|
This program is probebly use ActiveX control that should be register before exec program .
|
|
|
|
|
well you know your problem you used from services in VS.Net that maybe thet arent in another system
|
|
|
|
|
Hey guys,
I'm having some issues with an import function hook. Basically when I inject my DLL into the address space of a certain process, and a hook is performed on CreateFile , the process ends up crashing.
I am using Daniel Cavalcanti's DLL injection and API Hooking source found on:
http://www.planet-source-code.com/vb...=7528&lngWId=3
I think many are familiar with this. The DLL injector works fine. Its properly attached to the process. However, when the program runs, it hooks onto CreateFile , and as you can see in the source below, it writes to a file the value of lpFileName then returns the handle of CreateFile . The filename is written to the text file and is correct, however I get an unhandled exception error after it is returned.
You can also see that in Daniel Cavalcanti's API hooking source, he has a parameter for the HookImportedFunction where you have to supply the ordinal of the function. I didnt know what the ordinal of CreateFileA is so I removed that.
I know these may be some stupid questions, but I've googled for hours to find some answers or a solution to my problem.
1) Is CreateFileA an import or export function of the Kernel32.dll Module? If its exported then I may have to change the code around a bit.
2) What is it that I could be doing wrong thats causing my program to crash?
3) What would be the ordinal of CreateFileA in Kernel32.dll?
I included the source of my DLL for your perusal and hopefully someone can help me out because I have no idea how to fix this.
Thanks in advance,
Robbie
<br />
#include <windows.h><br />
#include <Dbghelp.h><br />
#include <fstream><br />
<br />
HANDLE hCreateFile(LPCTSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE);<br />
HANDLE htstCreateFile(LPCTSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE);<br />
<br />
PVOID HookImportedFunction(const char *Dll, const char *FuncName, void *Function);<br />
DWORD HookGeneralFunction(const char *Dll, const char *FuncName, void *Function, unsigned char *backup);<br />
void NumOut(char *format, ...);<br />
<br />
DWORD createFileAddr=0;<br />
BYTE backup[6];<br />
ofstream fout("C:\\dll.txt");<br />
<br />
BOOL APIENTRY DllMain( HMODULE hModule, DWORD fwReason, LPVOID lpReserved)<br />
{<br />
<br />
<br />
switch (fwReason)<br />
{<br />
case DLL_PROCESS_ATTACH:<br />
{ <br />
DisableThreadLibraryCalls(hModule);
fout << "In DLL process Attach" << endl;<br />
createFileAddr = HookGeneralFunction("Kernel32.dll", "CreateFileA", hCreateFile, backup);<br />
return true;<br />
<br />
}<br />
break;<br />
case DLL_THREAD_ATTACH:<br />
fout << "In DLL thread Attach" << endl;<br />
break;<br />
case DLL_THREAD_DETACH:<br />
fout << "In DLL thread detach" << endl;<br />
fout.close();<br />
break;<br />
case DLL_PROCESS_DETACH:<br />
{<br />
fout << "In DLL Process Detach" << endl;<br />
<br />
if(createFileAddr)<br />
WriteProcessMemory(GetCurrentProcess(), (void*)createFileAddr, backup, 6, 0);<br />
<br />
fout.close();<br />
return true;<br />
<br />
}<br />
break;<br />
}<br />
return false;<br />
}<br />
<br />
HANDLE hCreateFile(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)<br />
{<br />
<br />
fout << "Function call to CreateFileA and lpFilename is " << lpFileName << endl;<br />
<br />
HANDLE fHandle = CreateFile(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);<br />
<br />
fout << "The File handle is " << fHandle << endl;<br />
<br />
return fHandle;<br />
}<br />
<br />
<br />
<br />
HANDLE htstCreateFile(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)<br />
{<br />
<br />
WriteProcessMemory(GetCurrentProcess(), (void*)createFileAddr, backup, 6, 0);<br />
<br />
HANDLE ret = CreateFile(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);<br />
<br />
createFileAddr = HookGeneralFunction("kernel32.dll", "CreateFileA", htstCreateFile, backup);<br />
return ret;<br />
}<br />
<br />
<br />
-- modified at 6:15 Saturday 22nd July, 2006
|
|
|
|
|
Why in god's name do you do the following?
WriteProcessMemory(GetCurrentProcess(), (void*)createFileAddr, backup, 6, 0);
A process can access its own memory without resorting to the WriteProcessMemory API. That code is an inefficient and obfuscated way of doing the following:
memcpy((void*)createFileAddr, backup, sizeof(backup));
Steve
|
|
|
|
|
1. I’m trying to create an MFC library, the constructor of which reads from a file and updates an array.
CSentenceAr.h
#pragma once
#include <iostream>
class CSentenceAr
{
public:
CSentenceAr(LPCTSTR strFileToRead);
virtual ~CSentenceAr(void);
void sortSentences(bool bAscending);
int HowManyWords(const CString *pszWord);
private:
CStringArray m_strSentences;
};
#include "StdAfx.h"
#include ".\sentencear.h"
#define MAX_SENTENCES_PER_FILE 100
#define MAX_SENTENCE_LENGTH 1000
CSentenceAr.cpp
CSentenceAr::CSentenceAr(LPCTSTR strFileToRead)
{
CFile fileOp;
fileOp.Open(strFileToRead, CFile::modeCreate|CFile::modeRead);
char strLine[MAX_SENTENCE_LENGTH];
fileOp.Read(strLine,MAX_SENTENCE_LENGTH);
m_strSentences.Add(strLine);
}
CSentenceAr::~CSentenceAr(void)
{
}
I would like to read it line by line. Will the .Read method read the file to the end? How do I include the library file (preferably as a .dll, so I can add it as a reference) within another project to test it?
2. I tried to add an fstream object within this dll, but the compiler was returning the following error:
SentenceAr.cpp(12): error C2065: 'fstream' : undeclared identifier
Code:
#include "StdAfx.h"
#include ".\sentencear.h"
#include <fstream>
#define MAX_SENTENCES_PER_FILE 100
#define MAX_SENTENCE_LENGTH 1000
CSentenceAr::CSentenceAr(LPCTSTR strFileToRead)
{
CFile fileOp;
fstream mydamnFile;
fileOp.Open(strFileToRead, CFile::modeCreate|CFile::modeRead);
char strLine[MAX_SENTENCE_LENGTH];
fileOp.Read(strLine,MAX_SENTENCE_LENGTH);
m_strSentences.Add(strLine);
}
CSentenceAr::~CSentenceAr(void)
{
}
Jon
|
|
|
|
|
Well, I think your design could be improved for a start - why are you trying to read the entire file in the class constructor ?? not good - at best you should use it to initialize class member variables (like the filename) and such, and have a seperate method/function to perform the file read - but this is your issue, not mine
the guts of what you want is below, btw - notice 'ReadString'
>>>
CStdioFile XrefFile;
CString inString = "";
try {
XrefFile.Open(strInputFile, CFile::modeRead | CFile::typeText, NULL);
}
catch (CFileException e) {
//MessageBox("The file " + filename + " could not be opened for reading", "File Open Failed", MB_ICONHAND|MB_ICONSTOP|MB_ICONERROR );
return -1;
}
while (XrefFile.ReadString(inString)) {
// Do Something with inString
}
XrefFile.Close();
|
|
|
|
|
NOTE: CFile::Open DOES NOT throw any exception, so in your example try/catch is useless.
Ovidiu Cucu
Microsoft MVP - Visual C++
|
|
|
|
|
|
You are welcome. Anytime
Ovidiu Cucu
Microsoft MVP - Visual C++
|
|
|
|
|