|
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++
|
|
|
|
|
Here is a simple function which reads a text file line by line and fills a CStringArray:
void CSentenceAr::ReadTextFile(LPCTSTR pszFile)
{
m_strSentences.RemoveAll();
TRY
{
CStdioFile file(pszFile, CFile::modeRead);
CString strLine;
while(file.ReadString(strLine))
{
m_strSentences.Add(strLine);
}
}
CATCH(CFileException, e)
{
e->ReportError();
}
END_CATCH
}
NOTE: Once you can solve the problem using only MFC, it has no sense to mix STL (fstream) stuff.
However, when you do it, don't forget 'using namespace std', or write 'std::fstream'
Ovidiu Cucu
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for the solution
Jon
|
|
|
|
|
Hi,
I need someones help to Convert C++ strings to a C-style string (char*) in VC++ 6.0.
What I need to do is something as follows.
There is a string as,
string sh = “hello”;
I need to take the string in sh to
const char* tempd1 = .....
Thus I need someones help to do this.
Also if you can send me a way to convert a array of char(char st[]) to const char* .
Thanks
Dhananjaya
|
|
|
|
|
string s = "Hello";
const char *pCSTR = s.c_str();
Steve
|
|
|
|
|
Dhananjayak02 wrote: I need to take the string in sh to
std::string sh = "hello";
const char* tempd1 = sh.c_str();
or if u want the string to copy to another pointer
int n = sh.size();
char* c = new char[n + 1];
strcpy( c, sh.c_str());
Dhananjayak02 wrote: if you can send me a way to convert a array of char(char st[]) to const char*
char ch[20];
const char* pch = ch;
nave
|
|
|
|
|
Dhananjayak02 wrote: convert a array of char(char st[]) to const char* .
Before you try to *convert* types , you try to understand what are they.
<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??
|
|
|
|
|
|
Dhananjayak02 wrote: a array of char(char st[]) to const char* .
they are almost same thing!
"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
|
|
|
|
|
|
QuickDeveloper wrote: is there any function in VC to get the current screen resolution
Either take the window rect of desktop window or use
GetSystemMetrics() funtion with the following parameters
SM_CXSCREEN - for width
SM_CYSCREEN - for height
QuickDeveloper wrote: change the bitmap accordingly??
StretchBlt() can help
nave
|
|
|
|
|
You can use for get width and height and also see this code maybe it is some helpful to you
int x=GetSystemMetrics(SM_CXSCREEN)for x
in y=GetSystemMetrics(SM_CYSCREEN)for y
<br />
Graphics graphics(GetDC()->m_hDC);<br />
CRect rect;<br />
ImageAttributes imAttrib;<br />
Image *img;<br />
GetWindowRect(rect);<br />
ScreenToClient(rect);<br />
img = Image::FromFile(A2W("D:\\0.bmp")) ;<br />
graphics.DrawImage(img,Rect(0,0,rect.right,rect.bottom),<br />
0,0,img ->GetWidth(),img ->GetHeight(),<br />
UnitPixel,&imAttrib);<br />
|
|
|
|
|
QuickDeveloper wrote: 2)is there any function in VC to get the current screen resolution and change the bitmap accordingly??
Otherwise the only alternative is to make the application work only under specific resolution
SystemParametersInfo and StrechBlt api will help
QuickDeveloper wrote: Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"
good quote!
"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
|
|
|
|
|
hi
how can i hide a process?
|
|
|
|
|
farshad.f wrote: how can i hide a process?
hide from where?
nave
|
|
|
|
|