|
AFAIK, this 'if' check will not bring any noticable change in the performance. I know even more complex logging mechanisms are used in professional softwares. Also you can avoid logs (if that much necessary) in some extremely performance oriented functions.
Note: You may simplyfy the code (only look) using by using macros, so that repeated if blocks can be avoided.
Eg.
#define LOG(x) if( bLogEnabled ) { LogString( x ); }
- ns ami -
|
|
|
|
|
i m developing msn protocol 15 in c++.but i faced a problem in contact management (in accept and accept & add scenario).
plz any one help.
|
|
|
|
|
Well, you have to fix the problem.
Okay, that's probably the most usefull answer we can give you seing how detailed your question was.
|
|
|
|
|
actually my problem is that when some one adding, than actual msn received a request and there is three option one is decline another one is accept with right click button and accept without right click button so on all the three process whats the actual msn doing on the server side i want that source code.
|
|
|
|
|
I really think you need to ask the Microsoft Guys for that.
|
|
|
|
|
Hi
I have the raw image and want to read it to do convolution. The image has 5 bytes header making all my code goes wrong. Could anyone suggest a way to read it.
The resolution for the image is 190 X 243, 8 bits and 5 bytes of header. Because I use
fopen and fread to open,read the file and I do not how to use pointer to modify the starting point of reading.
This is the image http://edventure.ntu.edu.sg/bbcswebdav/users/z050016/leaf.raw [^]
Thank you very much.
|
|
|
|
|
Use fseek to shift the file pointer.
Maxwell Chen
|
|
|
|
|
Hello to all,
I am using Visual C++ Express 2008, now I am trying to create an
DLL and use it next.
I think I do everything allright, compile the code. This code
creates a DLL file.
Next, I created code to use that DLL, after compile there is no errors.
During debug, it appears this error:
Unhandled exception at 0x00000000 in useDLL1.exe: 0xC0000005:
Access violation reading location 0x00000000.
In this moment, I don't know if the mistake is from the DLL file
or from the following code( it is for loads DLL ).
I need, and I appreciate some help to understand where is the problem.
----------------------------------------------------------------
#include <windows.h>
#include <iostream>
using namespace std;
typedef int (CALLBACK* DLLfunc)(int);
#pragma once
int main()
{
int i, result;
HINSTANCE loadFcn = LoadLibrary("createDLL1.dll");
// Check to see if the library was loaded successfully
if (loadFcn != 0)
cout << "\n *LoadMe library loaded!\n";
else
cout << "\n *LoadMe library failed to load!\n";
DLLfunc loadedFcn;
loadedFcn = (DLLfunc)GetProcAddress(loadFcn,"functeste");
result=loadedFcn(30);
//result = 10;
cout << "hello DLL" << endl << endl;
cout << loadedFcn;
cout << endl << result;
cin >> i;
return 0;
}
------------------------------------------------------------------------
|
|
|
|
|
You may try step by step debug to check each line.
- ns ami -
|
|
|
|
|
Hi,
I think GetProcAddress can't resolve the function address at your DLL.
Can you check your DLL if the function is exported from your DLL (e.g. with Depency Walker from VC, I'm not sure that it is included at the express version).
Is your DLL-func exported like
extern "C" __declspec(dllexport) int functeste(int i){....}
Take also a look to this article and my comment.
http://www.codeproject.com/KB/DLL/rsLoadtimeDLL.aspx?fid=29819&select=1269812&tid=1074998[^]
HTH
Frank
modified on Friday, February 20, 2009 2:06 AM
|
|
|
|
|
From GetProcAddress documentation [^]:
Return Value
If the function succeeds, the return value is the address of the exported function or variable.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
In first, I want to thank all help.
- ns ami - : I already tryed that.
Debug stops on line:
"result=loadedFcn(30);"
I think that is when this command tries
to access to function into DLL.
Frank: Your tip was very fine. I did that.
"Depency Walker" didn´t get to read the DLL.
The problem seems to me, that is in DLL.
Now i'm trying to fix it. ...Another problem .
I made some alterations, and next I run "Depency Walker".
This time get to read the DLL.
But when I run debug, that code above,it occur the same error:
First-chance exception at 0x00000000 in useDLL1.exe: 0xC0000005:
Access violation reading location 0x00000000.
Unhandled exception at 0x00000000 in useDLL1.exe: 0xC0000005:
Access violation reading location 0x00000000.
CPallini:
I have tried your tip, and I added this line of code below
DWORD err = GetLastError();
it appears err = 127 ?? ( this meants it can't find the file ?? why? )
Could you help me?
Anyway, thanks for your concern.
|
|
|
|
|
Thanks to all, again.
I have reviewed all code and responses about this.
And I added some lines of code.
In the creation of DLL:
( extern "C" __declspec(dllexport) int functest(int i){....} )
And, using DLL:
typedef int (*MYFUNC)(int);
MYFUNC pnMyfunc = (MYFUNC)loadedFcn;
cout << " value of dll func = " << pnMyfunc(36) << endl;
FreeLibrary(loadFcn);
Next all DLL code:
#include <windows.h>
#include <iostream>
using namespace std;
typedef int (CALLBACK* DLLfunc)(int);
typedef int (*MYFUNC)(int); // --------------------------------- new line
#pragma once
int main()
{
int i;
DWORD err;
HINSTANCE loadFcn = LoadLibrary("createDLL1.dll");
err = GetLastError();
// Check to see if the library was loaded successfully
if (loadFcn != 0){
cout << "\n *LoadMe library loaded!\n";
DLLfunc loadedFcn;
loadedFcn = (DLLfunc)GetProcAddress(loadFcn,"functest");
MYFUNC pnMyfunc = (MYFUNC)loadedFcn; // -------------- new line
cout << endl << "hello DLL" << endl;
cout << " value of dll func = " << pnMyfunc(36) << endl;
cout << endl << " DLL func address " << *loadedFcn;}
else if (err){
cout << " erro - " << err;
cout << "\n *LoadMe library failed to load!\n";}
FreeLibrary(loadFcn);
cout << endl;
cout << endl << " **Free memory** " << endl;
cin >> i;
return 0;
}
|
|
|
|
|
MFC has the following two types CRgn and CRect
I know that the CRect Type has method like
BOOL IntersectRect(LPCRECT lpRect1,LPCRECT lpRect2)
But how could I find whether if two CRgn Objects have intersection or not?
|
|
|
|
|
Use CRgn::CombineRgn[^] in RGN_AND mode. This should return NULLREGION (or possible ERROR , I guess) if the intersection is empty.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thank you it helped me alot
|
|
|
|
|
I am part of a robotics team at my university and we are working on a robot for a competition. We are using a SICK LMS221 Lidar for obstacle avoidance and web cams to track the course boarders. The borders are spray-painted white or yellow lines and they can be broken lines, much like the ones that one would find on an expressway. The competition is pretty much an obstacle course in which we have to stay in between the lines and avoid obstacles.
My question is how could I make a webcam app that tracks the white lines. I want it to identify the lines vs the ground and somehow saturate the color so it only reads white or yellow. I have tried the "Real Time Object Tracking in C++" app on this site but it has to have a static background. My app needs to scan a moving "background" and identify white or yellow. I am a bit of a C++ noob but I really want to learn how to do this. My first "accomplishment" was getting a simple webcam app to compile and I understood how everything works accept for the fact that it uses the OpenGL library to wrap the image in 2D. There must be a simpler way to do this. Any help would be greatly appreciated!
|
|
|
|
|
This article[^] shows how to use Windows Image Acquisition to get images from a webcam. It's written in C#, but WIA is a COM library, so easy enough to access from C++.
It doesn't use OpenGL
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hello all,
working on a research project where I am taking a small exe and covert to hex pass it to another exe and have it execute the binary in a generic void * method returning void * but not sure how to do it, I know how to do inline ASM calls, but what do you feed the hexed up binary data to. Again this is for a research project NOT production as I am well aware of the potential hazards here. So any ideas anyone?
|
|
|
|
|
Hi,
an EXE file does not contain just executable code, it is a complex thing describing all that is needed to load several segments of code and data, load other required DLL files, etc.
You can launch an EXE file to run in a separate process by calling the Win32 function ShellExecute[^].
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
That's very likely not going to work. Executables rely on the OS loader to a) load the executables at a specific address (40000 hex), b) load DLLs and perform relocations on them, c) make data available at specific addresses. You could try to perform functionality equivalent to the OS loader, but I don't think it would work.
One approach that would involve a lot of work, but could well work, would be to implement a virtual process within the host process, a bit like how software like VMWare lets you run an OS on a virtual machine.
The first thing to do is get a very good understanding of the Windows OS loader and the PE executable format. This Wndows internals book[^] is an excellent place to start.
This article[^] is a good description of what's contained in a PE executable file, which shows you what the OS loader has to deal with when loading an executable.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Several years ago I had the task of writing a machine code generator for a script engine. In other words, a JIT mechanism to accelerate the execution speed of our scripts. I didn't have the first clue of how to even start but I figured out a test for the proof of principle.
First, I decided to implement a simple little function. It doesn't really matter what this is but it needs to be simple. Here is one to compare two integers :
int CompareValues( int valueA, int valueB )
{
int rc = 0;
if( valueA < valueB )
rc = -1;
else if( valueA > valueB )
rc = 1;
return rc;
}
Then I defined a type that is a pointer to a function with that prototype signature :
typedef int (*CompareFunc)( int valueA, int valueB );
Next I wrote a test program to do something like the following :
int TestMethod()
{
CompareFunc func = CompareValues;
int valueA = 42;
int valueB = 96;
int returnValue = (*func)( valueA, valueB );
return returnValue;
}
The next step is a little more involved. You have to go to the settings for your project and in the C++ section select Output Files and then enable the Assembly, Machine Code, and Source option. Now rebuild your test app and take a look at the machine code for the CompareValues function. Copy the machine code bytes and place them into an array of BYTEs :
static BYTE codeBytes[] = { ... };
Now you should be able to "invoke" this code with something like the following :
int TestMethod()
{
CompareFunc func = (CompareFunc)codeBytes;
int valueA = 42;
int valueB = 96;
int returnValue = (*func)( valueA, valueB );
return returnValue;
}
and that's basically it. You will probably have to experiment a little to make things work right like possibly using assembly statements to push your variables onto the stack before invoking the function and things like that.
It has been a long time, ten years or so, since I did this but I used a technique just like this to get started. My JIT compiler would emit the code bytes into a buffer and then execute them using a mechanism nearly identical to this.
You should be able to get the basics of this down fairly quickly. If you can't then this could be a very difficult project for you to accomplish.
|
|
|
|
|
THANKS!! THAT IS EXACTLY What Im looking to do, and the same sort of project actually. THANKS AGAIN
|
|
|
|
|
Please please help with this simple Q from a C++ newbie....I spent hours trying to find the answer online...
I want to run this on a linux box. Open a file containing a list of file names and then run a linux commands on each of the list for example:
The file contains a list of files names eg:
test
test1
test2
test3
How do I code in C so that it opens the file and then foreach of the elements do a system command eg: ls
in perl it would be something like:
#!/usr/local/bin/perl
while(<>){
chomp;
$cmd="ls $_";
system($cmd);
print "$cmd\n";
}
Thanks in advance!
|
|
|
|
|
Use fgets to read individual lines from a file.
Use strcat to append the file name to the command (just make sure the command is in a long enough string to start with).
C has a system function just like Perl as well.
It's easier in C++, using std::getline to read lines from a file and the std::string class to build the command:
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
int main(int argc, char** argv)
{
std::ifstream f(argv[1]);
std::string s;
while (std::getline(f, s))
{
system((std::string("ls -l ") + s).c_str());
}
}
Easy enough (and works on OS X, which is close enough to Linux)
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|