|
Please, read the posting guidelines before posting (e.g. use the code tag to format your code properly).
dconnell wrote: How to access and change the value of an element of a foreign (same program, different routine) array
You can't because the array only exists in the scope of the function. Outside the function it doesn't exist.
However, what you could do is declare this array as a class member of the CAHADlg class. This way, it's lifetime is the same as your class, and you can access it from whatever function of the class.
|
|
|
|
|
I wrote some of the programs in Visual Studio and some of them in TASM and NASM. I've encrypted a program I want to hide using an ASM program that does a simple xor on the program. (I did this so no one may know how to write the code I've created, not for malware purposes, but so no one could steal or re-engineer my program.) Now I'm having issues executing the code which is now in memory. Will I need to use a higher level function like those in C++ or MASM to execute the code? I can't figure out how to access it. Many of my methods end in failure to execute. I'm sorry for the vagueness of my questions, but I figure I've been specific enough for help.
|
|
|
|
|
BobMMarley wrote: but I figure I've been specific enough for help.
Not really.
How are you loading the executable into memory? Are you using a PE loader stub which uses an XOR over the code section and then jumps into the original entry point?
Or have you used an XOR on some machine instructions and stored them into a string? If this is the case then the memory will be marked as non-executable and could fail. You can use the VirtualProtectEx Function[^] to modify the memory at that location and give it PAGE_EXECUTE_READWRITE permissions. Alternatively you cound use the VirtualAllocEx Function[^] to allocate some executable memory and copy the bytes into there.
Some documentation:
Data Execution Prevention[^]
DWORD dwLen = sizeof(YourShellCode);
LPVOID lpMemory = VirtualAllocEx(GetCurrentProcess(),0,dwLen,MEM_COMMIT,PAGE_EXECUTE_READWRITE);
CopyMemory(lpMemory,YourShellCode,dwLen);
Best Wishes,
-David Delaune
|
|
|
|
|
Hey Guys,
I have a project I'm using programmed in Visual C++ 6. It's a simulation package that needs to use double precision variables. Because it is a non linear simulation package I need to store a lot of data as Global variables.
My question is how do I speed up access to these variables. Let me illustrate with an example. I came up with my own sqrt function. For my first cut for estimating the mantissa I used a polynomial curve fit and it blew the standard sqrt function away. Unfortunately the accuracy was awful. So I figured I would be clever and I would implement a global lookup table, with regular divisions. I looked at the code and I figured man this is going to be good. Well it was dog slow.
So it dawned on me that using globals while good for code management is not good for speed. I'm just wandering does anyone have any suggestions.
Thanks in advance.
Danny
|
|
|
|
|
Danny Nowlan wrote: Because it is a non linear simulation package I need to store a lot of data as Global variables
I'm not sure that necessarily follows...but anyway.
Danny Nowlan wrote: So I figured I would be clever and I would implement a global lookup table, with regular divisions
Why regular intervals? You want to vary the intervals with the rate of change of the curve, so you're getting a good approximation to the curve with a set of lines.
I've written linear interpolating table lookups for embedded systems - we generally do a binary search over the independent variable to find the points that surround the input, then linearly interpolate between those two. One optimisation that often works is to remember the results of the last lookup (the indices of the two points surrounding the last input) - our systems vary slowly, so the current input often falls in the same range as the last input.
Danny Nowlan wrote: So it dawned on me that using globals while good for code management is not good for speed
Wouldn't have thought the global-ness (or otherwise) of variables would impact the speed of using/writing them. I avoid global variables 'cause they make it too easy to design systems with high coupling between modules - that's bad.
|
|
|
|
|
stdext::hash_map[^]can give you better performance than std::map. std::vector (sorted) also is an option. But map or hash_map will consume more memory than std::vector. If your table is not too big, it's better to implement using global arrays where you can access in constant time ( O(1) ).
Just google, you can see lot of discussion around this topic.
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Hi,
the problem with global data is every one can access them, which also means the compiler has to allow for data changes all the time, so the data needs to be reloaded into registers/accumulators all the time. One way to improve this is to use local pointers to point into your global arrays. So for each global array you are interested in, create a local (and constant) pointer that points at it, then keep using the local pointers.
I have been designing two floating-point packages in a previous life, and I did study quite a lot of existing ones. I was very much surprised by the amount of code and complexity they were willing to add in order to shave off a few percents of execution time.
So I doubt very much you would come up with something revolutionary, I would rather not trust your initial measurements; blowing away the current implementation by something that has awful accuracy is no good: the standard library has to be accurate up to 1 or 2 of the lowest bits. Of course, if your applications don't need such accuracy, there are certainly faster algorithms to get that.
But don't let me discourage you, when and if you really get good results, I hope we will all hear from you.
|
|
|
|
|
Will calling CreateFont(-8, 0, 0, 0, 0, FALSE, FALSE, FALSE, 0, 0, 0, 0, 0, TEXT("small fonts")) always create the exact size font on all systems (assuming the "small fonts" font is present)? For example, would the zero character always be exactly 4 pixels wide and 6 pixels high?
|
|
|
|
|
Seems like it ought to, presuming 1 device unit == 1 pixel. I'd suggesting trying it to see?
|
|
|
|
|
Hi,
Yes. CreateFont does not create DPI-aware fonts.
Best Wishes,
-David Delaune
|
|
|
|
|
Complete error message is:
error RC2170 : bitmap file res\filelarge.png is not in 3.00 format
MSDN says:
Error Message
bitmap file filename is not in 3.00 format
Bitmaps using the Windows version 2.x format cannot be used in version 3.x resource files. The bitmap must be redrawn or converted to 3.x format.
Does anyone know of a tool that would convert an existing toolbar from 2.x format to 3.x format?
A C++ programming language novice, but striving to learn
|
|
|
|
|
Looking at the file extension it appears that it is not a bitmap file at all. This is an off-the-cuff suggestion, but have you tried opening the file in MS Paint and saving it as a bitmap?
--
gleat
http://blogorama.nerdworks.in[ ^]
-- Number Two's eyes narrowed and became what are known in the Shouting and Killing People trade as cold slits, the idea presumably being to give your opponent the impression that you have lost your glasses or are having difficulty keeping awake. Why this is frightening is an, as yet, unresolved problem. -- HHGTG
|
|
|
|
|
Try editing the .rc file manually and changing the type for res\filelarge.png from BITMAP to PNG.
|
|
|
|
|
GREAT!. concise and direct. Thanks
|
|
|
|
|
Hi,
I am new to Visual C++ Windows Forms Application (VS 2008) and I have a problem.
I nedd to develope an application, which uses WinPcap http://www.winpcap.org/[^].
My problem is as follows:
In the Form1.h file a have a method, in which I want to create an object of a class. Always, when I am compiling, I get the error msg: errorC2605 Undeclared identifier.
The code looks like this:
class Polaczenie
{
private:
pcap_if_t *alldevs;
pcap_if_t *d;
int inum;
pcap_t *adhandle;
char errbuf[PCAP_ERRBUF_SIZE];
public:
Polaczenie()
{
Initialise();
}
private:
void Initialise()
{
RetrieveDeviceList();
}
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data);
void RetrieveDeviceList()
{
Form1 ^f1 = gcnew Form1();
String ^_name;
if(pcap_findalldevs(&alldevs, errbuf) == -1)
{
f1->SetStatusText("Error in pcap_findalldevs: " + gcnew String(errbuf));
exit(1);
}
for(d=alldevs; d; d=d->next)
{
_name = gcnew String(d->name);
if (d->description)
_name += " " + gcnew String(d->description);
else
_name += " (No description available)";
f1->FillNetworkAdapterList(_name);
}
}
};
and I want to create an object of this class in this file in the method: CheckNetAdapters
#pragma once
namespace Something {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO;
using namespace System::Text;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::StatusStrip^ statusStrip1;
private: System::Windows::Forms::SplitContainer^ splitContainer1;
private: System::Windows::Forms::Button^ btStop;
private: System::Windows::Forms::Button^ btStart;
private: System::Windows::Forms::ComboBox^ comboBoxNetAdap;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel1;
private: System::Windows::Forms::ProgressBar^ pgBarSpace;
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->statusStrip1 = (gcnew System::Windows::Forms::StatusStrip());
this->toolStripStatusLabel1 = (gcnew System::Windows::Forms::ToolStripStatusLabel());
this->splitContainer1 = (gcnew System::Windows::Forms::SplitContainer());
this->pgBarSpace = (gcnew System::Windows::Forms::ProgressBar());
this->btStop = (gcnew System::Windows::Forms::Button());
this->btStart = (gcnew System::Windows::Forms::Button());
this->comboBoxNetAdap = (gcnew System::Windows::Forms::ComboBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->statusStrip1->SuspendLayout();
this->splitContainer1->Panel1->SuspendLayout();
this->splitContainer1->SuspendLayout();
this->SuspendLayout();
this->statusStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->toolStripStatusLabel1});
this->statusStrip1->Location = System::Drawing::Point(0, 323);
this->statusStrip1->Name = L"statusStrip1";
this->statusStrip1->Size = System::Drawing::Size(762, 22);
this->statusStrip1->TabIndex = 0;
this->statusStrip1->Text = L"statusStrip1";
this->toolStripStatusLabel1->Name = L"toolStripStatusLabel1";
this->toolStripStatusLabel1->Size = System::Drawing::Size(109, 17);
this->toolStripStatusLabel1->Text = L"toolStripStatusLabel1";
this->splitContainer1->Dock = System::Windows::Forms::DockStyle::Fill;
this->splitContainer1->Location = System::Drawing::Point(0, 0);
this->splitContainer1->Name = L"splitContainer1";
this->splitContainer1->Panel1->Controls->Add(this->pgBarSpace);
this->splitContainer1->Panel1->Controls->Add(this->btStop);
this->splitContainer1->Panel1->Controls->Add(this->btStart);
this->splitContainer1->Panel1->Controls->Add(this->comboBoxNetAdap);
this->splitContainer1->Panel1->Controls->Add(this->label1);
this->splitContainer1->Size = System::Drawing::Size(762, 323);
this->splitContainer1->SplitterDistance = 185;
this->splitContainer1->TabIndex = 1;
this->pgBarSpace->ForeColor = System::Drawing::SystemColors::HotTrack;
this->pgBarSpace->Location = System::Drawing::Point(30, 269);
this->pgBarSpace->Name = L"pgBarSpace";
this->pgBarSpace->Size = System::Drawing::Size(120, 10);
this->pgBarSpace->Step = 5;
this->pgBarSpace->Style = System::Windows::Forms::ProgressBarStyle::Marquee;
this->pgBarSpace->TabIndex = 8;
this->pgBarSpace->Value = 25;
this->btStop->Enabled = false;
this->btStop->Location = System::Drawing::Point(53, 171);
this->btStop->Name = L"btStop";
this->btStop->Size = System::Drawing::Size(75, 23);
this->btStop->TabIndex = 7;
this->btStop->Text = L"Stop";
this->btStop->UseVisualStyleBackColor = true;
this->btStop->Click += gcnew System::EventHandler(this, &Form1::btStop_Click);
this->btStart->Enabled = false;
this->btStart->Location = System::Drawing::Point(53, 133);
this->btStart->Name = L"btStart";
this->btStart->Size = System::Drawing::Size(75, 23);
this->btStart->TabIndex = 6;
this->btStart->Text = L"Start";
this->btStart->UseVisualStyleBackColor = true;
this->btStart->Click += gcnew System::EventHandler(this, &Form1::btStart_Click);
this->comboBoxNetAdap->FormattingEnabled = true;
this->comboBoxNetAdap->Items->AddRange(gcnew cli::array< System::Object^ >(3) {L"karta sieciowa_1", L"karta sieciowa_2",
L"..."});
this->comboBoxNetAdap->Location = System::Drawing::Point(30, 76);
this->comboBoxNetAdap->Name = L"comboBoxNetAdap";
this->comboBoxNetAdap->Size = System::Drawing::Size(121, 21);
this->comboBoxNetAdap->TabIndex = 5;
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(31, 49);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(119, 13);
this->label1->TabIndex = 4;
this->label1->Text = L"Wybierz kartę sieciową:";
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(762, 345);
this->Controls->Add(this->splitContainer1);
this->Controls->Add(this->statusStrip1);
this->Name = L"Form1";
this->Text = L"Form1";
this->statusStrip1->ResumeLayout(false);
this->statusStrip1->PerformLayout();
this->splitContainer1->Panel1->ResumeLayout(false);
this->splitContainer1->Panel1->PerformLayout();
this->splitContainer1->ResumeLayout(false);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void btStart_Click(System::Object^ sender, System::EventArgs^ e) {
btStart->Enabled = false;
btStop->Enabled = true;
}
private: System::Void btStop_Click(System::Object^ sender, System::EventArgs^ e) {
btStart->Enabled = true;
btStop->Enabled = false;
}
public: System::Void SetStatusText(String ^_text)
{
statusStrip1->Text = _text;
}
public: System::Void FillNetworkAdapterList(Object ^_item)
{
comboBoxNetAdap->Items->Add(_item);
}
private: System::Void CheckNetAdapters()
{
}
};
}
btw, any other advice about my code will also be very welcome.
|
|
|
|
|
Are you missing an #include for a required header file?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
No, I don't think so.
When I am compiling the code, like I put it on the site, everything goes ok, when I put the code
Polaczenie ^p = gcnew Polaczenie(); I get the errror I wrote above, even if both classes share the same namespace
|
|
|
|
|
Sorry, I missed where you stated which identifier was undeclared.
Polaczenie is not a managed class so you can't allocate a Polaczenie
object with gcnew.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I don't understand what you have in mind?
Can you give me some example please?
|
|
|
|
|
I don't have anything in mind
The class is not a managed (ref) class, so you have to allocate an object of the class with new, not gcnew.
Polaczenie *p = new Polaczenie();
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I tried that already. The same error plus additionally syntax error: identifier 'Polaczenie'.
When I changed the the class to a managed class with ref (I didn't know it is called like this), I had additionally an error with many of the variables of my Polaczenie class.
|
|
|
|
|
Doktor wrote: I tried that already. The same error plus additionally syntax error: identifier 'Polaczenie'.
I'm not entirely clear on the structure of your code and what is in which file,
but the compiler cannot possibly know what a Polaczenie is unless the declaration of
Polaczenie is visible "above" the code that tries to use it. If the declaration is in a
separate file, you can use something like #include "headerthatdeclaresPolaczenie.h".
Doktor wrote: When I changed the the class to a managed class with ref (I didn't know it is called like this), I had additionally an error with many of the variables of my Polaczenie class.
That's a whole new thing in a different language - C++/CLI. To do that you
need a firm understanding of .NET classes and data types, along with knowing
the C++/CLI language.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
class Form1 - > class with the whole design of the application
class Polaczenie -> a class in which I will get access to pc's network adapters.
After your suggestion I changed the classes, here what came out:
When the code of class Form1 was before Polaczenie, I could make an object of class Form1 in Polaczenie, but not an object of class Polaczenie in Form1. When I put the class Polaczenie before Form1 it went the opposite way. But I needed booth, I mean I need an object of class Form1 in class Polaczenie and an object of class Polaczenie in Form1. I will rearange my code and I think I can solve this matter now.
Thank you very much for your help.
|
|
|
|
|
your class Polaczenie declare under with namespace?? plus please post it into correct forum, this is unmanaged vc++/mfc forum.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Hey guys,
I am very new to programming (i've taken an intro course) but i know my way around several concepts in C++.
This much being said; i need some help.
I am trying to create a program that can be set as an automatic task that will save files from a backup server to a separate storage unit (mostly USB drives) and simultaneously change the file's name as well.
The farthest i've gotten so far is to figure out some little pieces of the project, but mostly i need help with:
1: How do i program it to search and validate a filename? (the file to be saved from the server) Also i need it to find the size of the file so that i know it will fit in the storage space(these are very large files).
2: How do i change the name of the file to another names with the date (such as 11-11-1111) added on the end?
3: How do i make this into a .exe program that can be run automatically?
Well that's it, i know that this forum is not some kind of genie, no i am not asking as a school project (that class ended long ago). I also know that posting here won't serve to answer my problems but the help provided (of any kind) would be appreciated. Code is nice but not needed if i can figure this thing out.
Thanks
~Mike
|
|
|
|
|