|
"double" is 8 bytes long in C...
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
Thanks Igor.
I picked up on that typo later on, too; however, the major issue remains: why does it crash when I supply the memory address to C++ dll for the second time for deallocation. Is the double* pointer a value of a "Long" type (4 bytes)?. If it is, then it doesn't really make sense why it's not working. Unless the memory addresses are wiped out by the time the DLL function exists.
|
|
|
|
|
>> then it doesn't really make sense why it's not working. <<
I agree, it doesn't make sence...
>> Unless the memory addresses are wiped out by the time the DLL function exists. <<
No, the memory addresses are not wiped out, because you are managing to access values from your VB code (I assume). What is wiped out is Runtime heap allocation info (like MCB blocks and etc). That can only be explained by DLL unloading after each call. I'm not GURU in DLL calls from VB, but it would be interesting to see how you declare those exported C functions in VB (Alias or etc).
What I recommend is to check the lifespan of your DLL, because your DLL code is available to you: put MessageBox or Debug breakpoints in DllMain or InitInstance/ExitInstance in DLL_PROCESS_ATTACH/DETACH and see when DLL loads/freed. That may give you some answers.
Also, you may set breakpoints/MessageBoxs in QrgAlloc( double* dArray ) and QrgFree( double* dArray ) and see if dArray you received in QrgFree is the same as dArray you return from QrgAlloc...
Alternatively, you may consider the following sequence in what you are doing:
imlement your VB/C code in the following manner:
1. Change QrgAlloc( double* dArray ), so it will be able to accept NULL argument as dArray --> in that case, should just return length of next allocation;
2. Allocate array in your VB code equal to the value of QrgAlloc returned on step 1;
3. Call now QrgAlloc( double* dArray ) with dArray equal to VB array allocated on step 2...
So, you don't have to allocate/free anything in C...
Regards
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
BTW: If you find out that VB unloads your DLL after each function call -- you can use the following trick to keep your DLL running.
Put extra LoadLibray as in here:
static HINSATNCE hInst = NULL;<br />
short _stdcall QrgAlloc( double* dArray )<br />
{<br />
if(!hInst)<br />
hInst = LoadLibrary("YourDllNameHere.dll");<br />
...
}<br />
short _stdcall QrgFree( double* dArray )<br />
{<br />
if(hInst)<br />
{<br />
FreeLibrary(hInst);<br />
hInst = NULL;<br />
}<br />
...
}
Not as beautiful, but may resolve the problem...
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
I've just realized that you basically have a BUG in your code.
If you are using default VB calling conventions then you are passing refference to l from VB to QrgAlloc => therefore your QrgAlloc function should be declared and implemented like that:
short _stdcall QrgAlloc( long* l)<br />
{<br />
double* dArray = new double[ 2 ];<br />
dArray[ 0 ] = 2.34;<br />
dArray[ 1 ] = 2.55;<br />
*l = (long)dArray;<br />
return 1;<br />
}
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
Experiment and find out. From memory, I think VB loads and unloads DLLs every time you call a function.
To be honest, once we start getting into context I would recommend writing a COM component. Using COM components is easier from VB6 anyway.
|
|
|
|
|
Hi!
How I can get the docking location (right, left, top or bottom) of a control bar?
|
|
|
|
|
how does one hide a folder from other people?
http://www.codeproject.com/tools/FolderHide.asp[^] says it makes the folder act like a shortcut to system folders (like Recycle Bin, Control Panel, etc.), but sadly, the tool came without source code.
|
|
|
|
|
You could try and notify the article's author. Others have made posts about it, so hopefully the source code will appear shortly. I suspect the article will be deleted otherwise (at least that's the impression that I got from Chris).
Otherwise, you may just have to use SetFileAttributes() .
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Hi,
I am sorry that I am asking a question not relevant to this section of MessageBoard, but I hope that somebody can help me out.
I use the WriteFile function in my MFC application to write data to a File from a Buffer.
When I see open the file, I see strange characters, while my data in the Buffer contains only numbers.
What can be the problem?
Thanks in Advance,
Deepak Samuel
|
|
|
|
|
A code snippet showing how you are writing to the file would be nice. How are you viewing the file once it's been written to?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
hDataFile = CreateFile(
DataFilename,
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL
);
pWin_Data[0] = (PWINDATA)WinBuff_1_Address;
WriteFile(
hDataFile,
pWin_Data[0],
sizeof(ULONG),
ptr,
NULL
);
CloseHandle(
hDataFile);
The File name is with the extension ".dat" and I opened it with notepad.
Deepak Samuel.
|
|
|
|
|
It looks like your code is writing a pointer address to the file. Is this the intention? If you want what the pointer is pointing to, use *(pWin_Data[0])
Roger Allen - Sonork 100.10016
If your dead and reading this, then you have no life!
|
|
|
|
|
It depends on how you open the file. Do you open it as text or binary? If you open it as binary you would see strange characters because you would be seeing the ascii interpretation of what the numeric values are. For instantce if you output the number 32 as binary it would appear as a space in a text file.
|
|
|
|
|
Hi
How can i get pointer to member function
class A{
virtual bool vfun(){
void* pfun = fun;
}
virtual bool fun(){
void* pvfun = vfun;
}
}
Why this code not compiled.
Thanks.
|
|
|
|
|
real_space_monkey wrote:
Why this code not compiled.
What message is the compiler giving you?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
The error of your code is in the declaration. In the function vfun() , you do not specify a pointer to function, but a pointer to void. Pointers to function have different type of declaration. According to MSDN, a pointer to function receives the following type of specification:
return-value (*variable)(param, ...) So, according to this, the pointers pfun and pvfun should be declared as:
void (*pfun)(void) = pfun;<DIV>
...<DIV>
void (*pvfun)(void) = pvfun;
Now you can call the functions through the pointers by issuing pfun() or pvfun() , as long as you're inside the correct context (inside the function the pointers are declared)
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
|
Hi,
I would like to know if there is some way
how to chance modeless dialog box into modal.
I mean I already have dialog created
and I just want to show it as modal.
Something like have choice:
dlg.ShowModal(); //is modal
or
dlg.ShowWindow(SW_SHOW); //is modeless
Thanx lot
Viliam
viliam
|
|
|
|
|
You want to change the behaviour while the dialog is visible?
It is probably easier to just close and reopen the dialog programmatically.
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
One solution is to derive a class from CDialog and do custom creation. Otherwise, one solution is to overrite OnClose(), etc. and keep the window from losing focus.
Kuphryn
|
|
|
|
|
|
Hi All,
Is there is any get the detail about the network devices like,
Name : HPINKJET
Type : Printer
Sub type : Laser
Make :
Model :
Serial No :
MAC Address:
If anyone of you know, can you please help me.
Thanks.
Regards,
A.Ilamparithi.
|
|
|
|
|
what network device do u mean?
a shared printer, a print server?
Don't try it, just do it!
|
|
|
|
|
Hi Alex...
Thanks for your interest.
By network device, i mean things like router, firewall, printer, etc..
Regards,
A.Ilamparithi
|
|
|
|