|
Hi,
Im trying to create a self extracting file. I have managed to do it for my home computer by getting the program to open a file pointer to its own exe file, but when i do this on other computers, I get a sharing violation. Is there a way around this?
Cheers
|
|
|
|
|
When I pass this pointer from Vb to C++ the value is not recieved. The pAcct variable always has the same value (0x0012fadc). If I change the C++ function so that it merely asks for a long value, or int, or even a BSTR, as an argument, the same thing happens (0x0012fadc). But, if I create the Account object in C++ and pass a pointer OUT to VB, that works fine. Or, if I take the value printed by the message box (0x0014F9F0), and copy that into pAcct after control has entered the GetAccount routine, everything works (the value printed from VB is valid). Its very perplexing.
Thanks for whatever advise you can give!
VB Code
<br />
Private Declare Function GetAccount Lib "C:\...\DataAccess.dll" (ByVal ptr As Long)<br />
<br />
Private Sub Form_Load()<br />
Dim Account As clsAccount<br />
Dim ptr As Long<br />
<br />
Set Account = New clsAccount<br />
ptr = ObjPtr(Account)<br />
MsgBox Hex(ptr), vbInformation <-- Prints the following value - 0x0014F9F0<br />
GetAccount ptr<br />
Label1.Caption = "Account Name = " & CStr(Account.AccountName)<br />
End Sub<br />
C++ Code
<br />
extern "C" void __stdcall GetAccount(_clsAccount* pAcct) <-- recieves the value 0x0012fadc<br />
{<br />
HRESULT hr = CoInitialize(0);
if (SUCCEEDED(hr))<br />
{<br />
_bstr_t bstr1(_T("TestInfo"));
pAcct->put_AccountName(bstr1); <-- causes access violation error <br />
CoUninitialize(); <br />
}<br />
}<br />
ANY suggestions will be IMMENSELY appreciated!
Thanks
|
|
|
|
|
Instead of getting the pointer to you object and then sending the pointer value 'ByVal',
why don't you just send a reference to the object?
rajdawg wrote:
Private Declare Function GetAccount Lib "C:\...\DataAccess.dll" (ByVal ptr As Long)
Private Declare Function GetAccount Lib "C:\...\DataAccess.dll" (ByRef ptr As Long)
rajdawg wrote:
Set Account = New clsAccount
ptr = ObjPtr(Account)
MsgBox Hex(ptr), vbInformation <-- Prints the following value - 0x0014F9F0
GetAccount ptr
Set Account = New clsAccount
GetAccount Account
VB by default uses Byref params
BTW I've never tried passing a class from VB to C. I wasn't sure it was possible. Structs, yes, but classes, with their code sections and all?
"It was when I found out I could make mistakes that I knew I was on to something."
-Ornette Coleman
|
|
|
|
|
Thanks for your reply.
I couldn't get that to work either. I received a ByRef Type Mismatch message from VB.
I have also seen an example where the decare statement would look like this...
<br />
Private Declare Function GetAccount Lib "C:\...\DataAccess.dll" (ByVal Account As Any)<br />
and the function call, in VB, would look like:
<br />
GetAccount Account<br />
but that does not work either.
I think you are right. I may need to build a structure that will represent this object in C++, and go that route. I'll keep researching.
Thank you for your response. This is very interesting/frustrating/humbling stuff.
thanks again.
roger
|
|
|
|
|
how to get the number of digits after the decimal point
ex :
Input : 5.1234
Expected Output : 4
i wrote this code but there are wornings..
what is wrong here ??
double input;
int x=input; // so x=the integeral part of input
int y=input-x; // so y=the fractional part
while(y>0)
{count++;
input*=10;
x=input;
y=input-x;
}
plz help me !!
elmahdy
|
|
|
|
|
you won't get the fractional part in y because it is an int.
|
|
|
|
|
I'm guessing there are a lot of ways to do this. How about this!
double input;
int Num = static_cast< int >( input );
intput -= static_cast< double >( Num );
You should now just have the .XXXX
Char szData[1024];
ssprintf( szData, "%f", &Input );
int iLengt = strlen( szData ) - 2; //For the zero & the '.'
This can give you a start.
Larry J. Siddens
Cornerstone Communications
TAME THE DOCUMENT MONSTER
www.unifier.biz
|
|
|
|
|
Any one know if it’s possible to change or add to the environment variables of the calling process?
I know it's really easy to change the current processes env vars, and child process env vars...
Thanks,
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
I don't think it is possible. What a you trying to do?
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
I am trying to write a console executable that can be used in a batch file to change the environment vars of the batch file depending on user input and or contents of a text file.
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
Hi,
I'm trying to add a submenu into the Main File Menu, and I want to populate the submenu dynamically. But, I'm getting an error on AppendMenu() at runtime.
Here is what I'm doing:
CMenu* menu_bar = AfxGetMainWnd()->GetMenu();
CMenu* file_menu = menu_bar->GetSubMenu(0);
for (int iCount =0; iCount<maximum ;="" icount++)
{
if="" (!uniquehierarchyname[icount].isempty())
{
hierarchysubmenu.appendmenu="" (mf_string,="" id_base_command="" +icount,="" uniquehierarchyname[icount]);
}
}
file_menu-="">AppendMenu (MF_POPUP, (UINT)HierarchySubmenu.m_hMenu, "&Add Hierarchy from Submenu");
|
|
|
|
|
When should I return an error code instead of throwing an exception and vice versa?
Rickard Andersson
Here is my card, contact me later!
UIN: 50302279
Sonork: 37318
Interests: C++, ADO, SQL, Winsock, 0s and 1s
|
|
|
|
|
That is such a massive issue. If you are making a C++ program returning error codes is dumb because you need to return something sensible in proper OO design.
I recommend you buy yourself a C++ book because almost any is bound to have a long description with example code.
I say: never return an error code. With the exception of int main() of course
dog_spawn
http://www.hatekill.com[^]
|
|
|
|
|
dog_spawn wrote:
recommend you buy yourself a C++ book
I do have one. But doesn't say when to use exceptions
dog_spawn wrote:
I say: never return an error code. With the exception of int main() of course
Is that real OO? Cool, I'll see what I can do with my class framework I'm current designing.
Rickard Andersson
Here is my card, contact me later!
UIN: 50302279
Sonork: 37318
Interests: C++, ADO, SQL, Winsock, 0s and 1s
|
|
|
|
|
Get into the habit of handling errors via exception handling. Here's more.[^]
Regards,
Alvaro
Hey! It compiles! Ship it.
|
|
|
|
|
Great! Thaks alot for clearing things up!
Rickard Andersson
Here is my card, contact me later!
UIN: 50302279
Sonork: 37318
Interests: C++, ADO, SQL, Winsock, 0s and 1s
|
|
|
|
|
Exceptions are for truly exceptional errors. Like the file you are working on has suddely disapeared, or you cant get enough memory etc. That Kind of things that you can never be sure when it happenes.
Return code , to the contrary are the everyday case of an error: All those stuff you know that can happen, but your routine can't cope with on itself, like a file can not be opened, user gave your parser too few arguments, the file format of your data is not as expected etc.
All this are things that happen quite often, and you can think of them easily, but your routine must rely on its caller to solve them (e.g. query the user, something your file-handling routines should do, as they are not part of the GUI).
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
I agree with (almost ) everything above, but also believe...
That you should only consider throwing exceptions when you fully understand the consequences of doing so, specifically issues to do with the overheads, resource aquistion and stack unwinding. Writing consistantly exception safe c++ code is extremely hard, even for the best programmers.
Herb Sutter and Scott Meyers have some superb articles on Exception safety, I strongly recommend you look at their material.
Error codes are appropriate in situations where performance is absolutely critical or exception safety is not an option. Two examples are some operating systems, old versions of CE AFAIK, and the standard IOStreams library.
The C/C++ Users Journal tend to spend a significant ammount of time covering this type of issue.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
In VC++ 6.0, Windows 2000, how to schedule a thread to run on a specific CPU?
Is there any APIs or methods?
Thanks,
Leo
|
|
|
|
|
|
Thanks.
|
|
|
|
|
Here's the situation:
class A
{
public:
friend ostream& operator<<(ostream& os, const A& a)
public:
void ShowExpandedInfo() { cout<<this <<endl; }
};
=================
class B : public A
{
public:
void RunOuterLoop();
};
=================
int main()
{
A a;
B b;
b.RunOuterLoop();
return 0;
}
==================
void B::RunOuterLoop()
{
ShowExpandedInfo();
}
The problem (as you all know) is that in activating ShowExpandedInfo (from RunOuterLoop), what gets shown, is B's data instead of A's.
Inside the 'friend' function is where I do formatting (etc.) of A's data prior to printing.
I've tried just about every trick and clever idea I could come up with, to get A's data to show, which the compiler dutifully shoots down every time.
The sample is not written in stone. It gets changed around with some of the various things I try. What is shown, is merely a starting point to demonstrate the general layout of code, and what I'm trying to accomplish.
I would be remiss if I didn't say one of the things I tried, was to use a 'const' reference of 'A' as a parameter of RunOuterLoop (and changed the code to suit that approach). It didn't work, since that simply showed and empty 'A'.
Thanks for any thoughts or ideas on how I can get A's object to show from 'B'?
William
Fortes in fide et opere!
|
|
|
|
|
Your design is actually wrong because operators of course cannot be virtual. Why don't you simply make a virtual toString() function that you call in the overloaded operator <<?
If you want to use polymorphism you really should be using pointers. I fail to see the point of your code.
You seem to have overcomplicated something that is very simple
|
|
|
|
|
It's because operators are not virtual why I used a friend function to do the overloading, and it's because friends are not inheritable why the function to show the data is declared and defined in the base class.
Polyphormism was actually one of the things I tried, which turned out to be more work without the solution I sought. I pretty much obtained the same result just as when I didn't use it, and it's because an object of a derived class can be treated an object of its corresponding base class, why I didn't see a need for other polymorphic attempts.
Instead of talking about overcomplicating something that you see as "simple", why didn't you present your "simple" solution?
William
Fortes in fide et opere!
|
|
|
|
|
I did present a simple solution. Reread my post?
|
|
|
|