|
I want to develop a firewall software with C++ Builder.But i don't know how can i start.Must i use a driver or anything else (Ndis,filter hook ....)Please tell me how can i start? What i need ?
what is ndis and winpkfilter ?
|
|
|
|
|
I doubt that C++ Builder supports C++/CLI. (i.e. please don't flood the forums )
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I have two questions really bothers me.
1. Is it possible to have .Net assembly with global functions so that I can add reference and use them in my application by ::globalfunctions?
2. I have one small solution with two projects: one to create the dll and the other is to consume it. In the application, I can see the intellisense recognize the member in the namespace. But when I compile, I got error 2039 "something" is not a member of "namespace".
here is the sample code:
[the code for the dll]
Int32 sometfunction()
{
return 0;
}
namespace Cards
{
public __value int somethingnew;
}
[The code consume it]
#include "stdafx.h"
using namespace System;
using namespace Cards;
Int32 main(void)
{
Int32 ddd = ::somefunction();
Int32 dkd = Cards::somethingnew;
return 0;
}
Since I already added the reference to the application, there is no need to use something like
#using <cards.dll>
Any help will be greatly appreciated. I believe this is the right forum to get answer( I posted this question friday to another forum no one even care about what I asked )
Devin
|
|
|
|
|
devinzhang wrote: Is it possible to have .Net assembly with global functions so that I can add reference and use them in my application by ::globalfunctions?
I doubt it, seeing as .NET generally forces OO ( does not allow anything global ). That's why, for example, you have a Math class full of static functions instead of a math library like C++.
devinzhang wrote: Since I already added the reference to the application, there is no need to use something like
I don't believe that is correct. The intellisense often finds stuff even if you've failed to scope it with using statements or explicit use of namespaces.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thank you Christian for the reply ,
1. I doubt it, seeing as .NET generally forces OO ( does not allow anything global ).
But does that mean if I have the global functions or variables in my source file the generated dll won't actaully contain the information about global functions or variables? or even if the dll contains the information of global functions or variables, I still cannot retrieve it?
What could be the best solution? I have a project mixing of lots of global functions and classes. I need to export several global functions. I want to use them in .Net way by just adding reference instead of using Dllimport in the application.
1. I don't believe that is correct. The intellisense often finds stuff even if you've failed to scope it with using statements or explicit use of namespaces.
I see. Sorry for missing the words after #using in my previous post. I mean #using Cards.dll on the top is not necessary if you already have it added in reference. #using namespace is always necessary and I did use it in my code.
I can see the global functions I declared in the object browser of the project but not in the created dll that I added as reference.
Also, as you can see I declared somethingnew in the namespace Cards, but I cannot see it in the created DLL, did I do something wrong?
Devin
|
|
|
|
|
devinzhang wrote: But does that mean if I have the global functions or variables in my source file the generated dll won't actaully contain the information about global functions or variables? or even if the dll contains the information of global functions or variables, I still cannot retrieve it?
It probably means you can't use them from managed code. I'm not sure.
devinzhang wrote: I have a project mixing of lots of global functions and classes. I need to export several global functions. I want to use them in .Net way by just adding reference instead of using Dllimport in the application.
You'd have to ask someone like Nish, but I'd be surprised if you can use your global stuff that way.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I posted a related question the other day regarding statics. My current thought is that you need to use a delegate.
I have not had a chance to try this myself and given the problems I have been having todate I may be wrong. I also want to pass a static data member around. I tried using tools->ILDasm to see if its being exported but am at the bottom of the learning curve at the moment being new to microsoft.
This is the example from msn web site.
// use_delegate.cpp
// compile with: /clr
using namespace System;
ref class SomeClass
{
public:
static void Func(String^ str)
{
Console::WriteLine("static SomeClass::Func - {0}", str);
}
};
ref class OtherClass
{
public:
OtherClass( Int32 n )
{
num = n;
}
void Method(String^ str)
{
Console::WriteLine("OtherClass::Method - {0}, num = {1}",
str, num);
}
Int32 num;
};
delegate void MyCallback(String^ str);
int main( )
{
MyCallback^ callback = gcnew MyCallback(SomeClass::Func);
callback("single");
callback += gcnew MyCallback(SomeClass::Func);
OtherClass^ f = gcnew OtherClass(99);
callback += gcnew MyCallback(f, &OtherClass::Method);
f = gcnew OtherClass(100);
callback += gcnew MyCallback(f, &OtherClass::Method);
callback("chained");
return 0;
}
|
|
|
|
|
Barry, thank you for the code and the idlasm.
From the idlasm, I can see all the global functions are there. Actually, I can use dllimport to import those functions before. I just want a .Net way to import it.
I created a simple .Net wrapper class with several static methods corresponding to the global functions I want to export. The code sample is like
Int32 GlobalFunc1()
{
return 0;
}
Int32 GlobalFunc2()
{
return 0;
}
namespace MyNameSpace
{
public __gc class MyWrapper
{
public:
static Int32 GlobalFunc1()
{
return ::GlobalFunc1();
}
static Int32 GlobalFunc2()
{
return ::GlobalFunc2;
}
}
}
Then in the application side after you adding the reference
using MyNameSpace
Int32 main()
{
MyWrapper::GlobalFunc1();
MyWrapper::GlobalFunc2();
return 0;
}
Barry, this solves my problem. I am not sure if this helps you. If you want to use the class in your global functions, I think you can directly create an instance of your class without using delegate.
Devin
|
|
|
|
|
I have some problem working with LPCTSTR. I have a function which accepts some argument of type LPCTSTR like someFunction(LPCTSTR arg) and when I try to use switch sommand on this argument it generates an error telling that switch can't be used with LPCTSTR type. Code is something like this:
swith(arg)
{
//Some code ...
}
and even when I check it with "if" it doesn't work too. Suppose that arg value is something like "test" which I can see by using AfxMessageBox(arg)., although it shows that arg value is "test" but this line of code doesn't work:
if(arg == _T("test"))
//this code doesn't work! Although arg is "test"
what's the problem with that?
... And nothing else matters!
|
|
|
|
|
|
You're new to C/C++, aren't you?
Strings in C and C++ are pointers to arrays of characters, ended with a special character having the value zero. If you do this: if(arg == _T("test")) you're not comparing the string values but the pointers. In your case, the input parameter is most likely a pointer pointing to some string array in your process' data segment. The literal "test" is in a read only segment. Due to this fact, the two strings are at different memory locations, and therefore the addresses in your pointer and literal are not equal, hence the failing test.
What you must do in order to compare strings for value equality, is that you have to compare the characters in the memory areas. That is best done using functions such as strcmp et al.
--
Pictures[^] from my Japan trip.
|
|
|
|
|
Hi friends,
There is problem in accessing mapped drives or remote machine from my vc++ service in Windows Server 2003 OS for example when I execute my program as services it fails but I am not facing any problem if I execute it as standalone program. I am having admin privilege. Below is the few of API I tried (where is S: is mapped drive in same domain)
API:
CreateFile and GetFileAttributes("S:\hello.txt")
Thanks,
Thomas
|
|
|
|
|
By default, access to the root directory from a service user is denied. It is suggested to use a standalone proxy program to perform such operations.
My blogs:
http://blog.joycode.com/jiangsheng
http://blog.csdn.net/jiangsheng
http://bloglines.com/public/jiangsheng
Command what is yours
Conquer what is not
---Kane
|
|
|
|
|
is there any way to use it as service instead of standalone
|
|
|
|
|
I tried with Admin user, local System account and tried direct path also like
"\\server\public_data\hello.txt" but no use. It has problem when running as a service in win2003k and as standalone no problem.
do anyone know how to give more permissions to services in win2003k os?
|
|
|
|
|
I am new to windows programming, and am using Visual Studio .Net 2003.
I have a standard managed form which contains a number of data entry fields (textboxes, radio buttons etc), and a couple of buttons.
One of the buttons (labelled Save) activates an event handler that calls two functions. The first function will perform some validation on the data entered in the form, and then displays a message on a second smaller form with an OK button. This OK button closes the form. The second function then formats some of the data, and will eventually write it to a file.
How do I stop the second function running until after the OK button on the form displayed by the first function is clicked ? Or, in other words, how do I stop the 2nd function from running until the first is complete.
The program so far is listed below, and the event handler concerned is called collegeForm::buttonSave.
Many thanks
#using
#using
#using
#using
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
__gc class collegeForm : public Form
{
public :
collegeForm();
private :
Label *labelSurname;
Label *labelForename;
Label *labelGender;
Label *labelDateOfBirth;
Label *labelAccomodation;
Label *labelSupportCode;
Label *labelCourseCode;
TextBox *surname;
TextBox *forename;
TextBox *courseCode;
TextBox *dateOfBirth;
ComboBox *supportCode;
GroupBox *gender;
RadioButton *male;
RadioButton *female;
GroupBox *accomodation;
RadioButton *parentalHome;
RadioButton *lodgings;
RadioButton *hallsOfResidence;
Button *save;
Button *clear;
MainMenu * mainMenu;
void buttonSave(Object *Sender, EventArgs *Args);
void buttonClear(Object *Sender, EventArgs *Args);
Int32 validateForm(void);
void formatNames(void);
};
__gc class errorMessage : public Form
{
public :
errorMessage();
errorMessage(String *);
private :
Label *message;
Button *ok;
void buttonOK(Object *Sender, EventArgs *Args);
};
errorMessage::errorMessage()
{
}
errorMessage::errorMessage(String * errorMessage)
{
this->Text = S"Error Message";
message = new Label;
message->Text = errorMessage;
message->Location = Point(25,100);
this->Controls->Add(message);
ok = new Button;
ok->Location = Point(180,120);
ok->Text = "OK";
ok->Click += new EventHandler(this,buttonOK);
this->Controls->Add(ok);
}
void errorMessage::buttonOK(Object *Sender, EventArgs *Args)
{
Close();
}
collegeForm::collegeForm()
{
this->Text = S"College Enrollment Database";
labelSurname = new Label;
labelSurname->Text = S"Surname";
labelSurname->Location = Point(25,100);
this->Controls->Add(labelSurname);
labelForename = new Label;
labelForename->Text = S"Forename";
labelForename->Location = Point(25,150);
this->Controls->Add(labelForename);
labelGender = new Label;
labelGender->Text = S"Gender";
labelGender->Location = Point(25,200);
this->Controls->Add(labelGender);
labelDateOfBirth = new Label;
labelDateOfBirth->Text = S"Date Of Birth";
labelDateOfBirth->Location = Point(25,250);
this->Controls->Add(labelDateOfBirth);
labelAccomodation = new Label;
labelAccomodation->Text = S"Accomodation";
labelAccomodation->Location = Point(25,300);
this->Controls->Add(labelAccomodation);
labelSupportCode = new Label;
labelSupportCode->Text = S"Support Code";
labelSupportCode->Location = Point(25,350);
this->Controls->Add(labelSupportCode);
labelCourseCode = new Label;
labelCourseCode->Text = S"Course Code";
labelCourseCode->Location = Point(25,400);
this->Controls->Add(labelCourseCode);
surname = new TextBox;
surname->Location = Point(125,100);
surname->Width = 200;
this->Controls->Add(surname);
forename = new TextBox;
forename->Location = Point(125,150);
forename->Width = 200;
this->Controls->Add(forename);
courseCode = new TextBox;
courseCode->Location = Point(125,400);
courseCode->Width = 100;
this->Controls->Add(courseCode);
dateOfBirth = new TextBox;
dateOfBirth->Location = Point(125,250);
dateOfBirth->Width = 200;
this->Controls->Add(dateOfBirth);
supportCode = new ComboBox;
supportCode->Location = Point(125,350);
supportCode->Width = 230;
supportCode->Items->Add(S"No Known Disability");
supportCode->Items->Add(S"Dyslexia");
supportCode->Items->Add(S"Blind or Partially Sighted");
supportCode->Items->Add(S"Deaf or Impaired Hearing");
supportCode->Items->Add(S"Mobility Difficulties or Wheelchair User");
supportCode->Items->Add(S"Personal Care Support Required");
supportCode->Items->Add(S"Mental Health Difficulties");
supportCode->Items->Add(S"Unseen Disability - Diabetes, Asthma");
supportCode->Items->Add(S"Two Or More Of The Above");
supportCode->Items->Add(S"Other Disability Not Listed");
supportCode->Text = S"No Known Disability";
this->Controls->Add(supportCode);
gender = new GroupBox;
gender->Location = Point(125,175);
gender->Size = Drawing::Size(300,55);
Controls->Add(gender);
male = new RadioButton;
male->Location = Point(25,20); // These are coords in group box
male->Text = S"Male";
gender->Controls->Add(male);
female = new RadioButton;
female->Location = Point(150,20);
female->Text = S"Female";
gender->Controls->Add(female);
accomodation = new GroupBox;
accomodation->Location = Point(125,275);
accomodation->Size = Drawing::Size(450,55);
Controls->Add(accomodation);
parentalHome = new RadioButton;
parentalHome->Location = Point(25,20);
parentalHome->Text = S"&Parental Home";
accomodation->Controls->Add(parentalHome);
lodgings = new RadioButton;
lodgings->Location = Point(150,20);
lodgings->Text = S"Lodgings";
accomodation->Controls->Add(lodgings);
hallsOfResidence = new RadioButton;
hallsOfResidence->Location = Point(275,20);
hallsOfResidence->Text = S"&Halls Of Residence";
accomodation->Controls->Add(hallsOfResidence);
save = new Button;
save->Location = Point(175,500);
save->Text = S"&Save";
save->Click += new EventHandler(this,buttonSave);
this->Controls->Add(save);
clear = new Button;
clear->Location = Point(350,500);
clear->Text = S"&Clear";
clear->Click += new EventHandler(this,buttonClear);
this->Controls->Add(clear);
mainMenu = new MainMenu();
MenuItem *menuFile = mainMenu->MenuItems->Add("&File");
menuFile->MenuItems->Add("&Validate");
menuFile->MenuItems->Add("&Save");
menuFile->MenuItems->Add("&Clear");
menuFile->MenuItems->Add("-");
menuFile->MenuItems->Add("&Exit");
MenuItem *menuHelp = mainMenu->MenuItems->Add("&Help");
menuHelp->MenuItems->Add("&About");
Menu = mainMenu;
}
void collegeForm::buttonSave(Object *Sender, EventArgs *Args)
{
validateForm();
formatNames();
}
void collegeForm::buttonClear(Object *Sender, EventArgs *Args)
{
surname->Text = S"";
forename->Text = S"";
courseCode->Text = S"";
dateOfBirth->Text = S"";
supportCode->Text = S"";
male->Checked = false;
female->Checked = false;
parentalHome->Checked = false;
lodgings->Checked = false;
hallsOfResidence->Checked = false;
}
Int32 collegeForm::validateForm(void)
{
errorMessage * em = new errorMessage("This is a test");
em->Size = System::Drawing::Size(400,200);
em->Show();
return(1);
}
void collegeForm::formatNames(void)
{
String * left;
String * right;
String * temp;
if (surname->Text->Length > 1)
{
temp = surname->Text;
left = temp->Substring(0,1);
right = temp->Substring(1,temp->Length-1);
left = left->ToUpper();
right = right->ToLower();
temp = String::Concat(left,right);
surname->Text = temp;
}
if (forename->Text->Length > 1)
{
temp = forename->Text;
left = temp->Substring(0,1);
right = temp->Substring(1,temp->Length-1);
left = left->ToUpper();
right = right->ToLower();
temp = String::Concat(left,right);
forename->Text = temp;
}
}
int __stdcall WinMain()
{
collegeForm *cf = new collegeForm();
cf->Size = System::Drawing::Size(600,600);
Application::Run(cf);
return 0;
}
Simon Cornish
Simon Cornish
|
|
|
|
|
Simon Cornish wrote: em->Show();
try this:
em->ShowDialog(this); //this will make a Modal dialog
If you are trying to display only error message, why you don't use:
MessageBox::Show()
|
|
|
|
|
Many thanks - all sorted.
|
|
|
|
|
How to attach an assembly dll to project in C++ for VC NET and use its namespaces?
9ine
|
|
|
|
|
9ine wrote: How to attach an assembly dll to project in C++ for VC NET and use its namespaces?
You need to add a reference.
|
|
|
|
|
How to do it?
Piece of code in VC++ please or where to plug it in in proj settings and how to use it then?
It is about the article:
DirectX >> General
Capture Sample with DirectX and .NET By Blas5
The source code for his application to use directx.capture.dll and dshownet.dll is in VB and it uses imports DirectX.Capture
but I need it in VC++ to use something like using namespace.
9ine
|
|
|
|
|
Which version of VC++ are you using?
In VC++ 2005, take [References] from the [Project] menu and click on [Add new reference]. You need to put the Project name in focus in Solution Explorer to get the required menu items in the [Project] menu.
|
|
|
|
|
try this:
#using "directx.capture.dll"
|
|
|
|
|
I use VC 2003 and it is
#using "directx.capture.dll"
using namespace DirectX::Capture;
9ine
|
|
|
|
|
Hello!
I need to make a skip list in my application and I decided to take code from Robert Sedgewick's book "Algorithms in C++", but faced one serious problem: the insert function sometimes failes. I don't know why. Here is it:
const int lgNmax = 10;
template <class Item, class Key>
class SkipList
{
private:
struct node{
Item item;
node **next;
int sz;
node(Item x, int k)
{
item = x;
sz = k;
next = new node*[k];
for(int i = 0; i < k; i++)
next[i] = 0;
}
};
typedef node *link;
link head;
Item nullItem;
int lgN;
...
int _randX()
{
int i, j, t = rand();
for(i = 1, j = 2; i < lgNmax; i++, j += j)
if(t > RAND_MAX / j)
break;
if(i > lgN)
lgN = i;
return i;
}
void _insert(link t, link x, int k)
{
Key v = x->item.Key();
link tk = t->next[k];
if(!tk || v < tk->item.Key()){
if(k < x->sz){
x->next[k] = tk;
t->next[k] = x;
}
if(k == 0)
return;
_insert(t, x, k - 1);
return;
}
_insert(tk, x, k);
}
public:
SkipList()
{
head = new node(nullItem, lgNmax);
lgN = 0;
srand((unsigned int)time(NULL));
}
void Insert(Item v)
{
_insert(head, new node(v, _randX(), lgN);
}
...
};
And the problem is with the 'if(!tk || v < tk->item.Key()){' line (marked with comment). The problem is that the tk sometimes becomes 0xfdfdfdfd. I can't understand why and how to avoid this. It happens at the first iteration of _insert() when t = head. And this usually happens at 300th - 600th insertion. Could you help me to remove the bug?
Thank you in advance!
|
|
|
|
|