|
Hey Guys,
I got a piece of Unix Code but I have to make it run under Windows. Unfortunately I contains the function mmap (a Unix Function). Fortunately there is this nice DLL called cygwin1.dll which gives you some Unix Functions.
<br />
HINSTANCE hDll = LoadLibrary("cygwin1.dll");<br />
if(hDll)<br />
{<br />
printf("DLL Loaded !\r\n");<br />
FARPROC mmap = GetProcAddress(hDll,"mmap");<br />
if(mmap)<br />
{<br />
printf("Function found !\r\n");<br />
mydata= mmap(mydata, myLength,PROT_READ,MAP_PRIVATE,fd,0);<br />
}<br />
else<br />
{<br />
printf("Function not found!\r\n");<br />
}<br />
}<br />
else<br />
{<br />
printf("Failed to load DLL!\r\n");<br />
}<br />
This is the code I use. But when I then try to call the mmap function my compiler tells me that I'm passing to many arguments to mmap.
Normally I don't load libraries at runtime. So please help me
|
|
|
|
|
Hey,
You're getting a function pointer back, but GetProcAddress can't possibly know what the function definition of mmap is so you have to tell it.
Assuming that you are using the results from "man mmap"
#include < sys/mman.h >
void* mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);
then you would do something like this
#include < windows.h >
typedef void* (CALLBACK* PFNMMAP)(void*, size_t, int, int, int, off_t);
PFNMMAP pmmap;
if( (pmmap = GetProcAddress(dllHandle, "mmap"))) {
}
now pmmap is a function pointer with the right signature -- ie of type PFNMMAP. Oh yes, modify CALLBACK based on the way the dll export table was declared (it should work for __declexport).
Also, there are two types of libs on windows. One, called a .lib, is code made to be statically linked into a file. The other, for your convenience also called a .lib, is code that is statically linked at compile time but just thunks to a dll. The latter is often more convenient as it will handle the LoadLibrary and GetProcAddress stuff for you.
The downside to using import libs is that windows tries to load the dll before your main / WinMain is called. If it can't find the dll you never get control. At least with manual LoadLibrary calls you can be intelligent about telling the user just what you can't find and what he or she ought to do about it.
PS: I don't have a compiler on this computer so I can't promise any of this works.
HTH
earl
|
|
|
|
|
How many parameter in this function mmap and use mmap with correct parameter
whitesky
|
|
|
|
|
what's the difference between file->new and window->newwindow in MDI project(pj name mydoc)?
why use file->new, the newfile name is mydoc1(or mydoc2,mydoc3,mydoc4.......)
but window->new Window, the new doc name is mydoc1:2 (or mydoc1:3, mydoc1:4, mydoc2:2.......)?
|
|
|
|
|
hi,I need your help......
|
|
|
|
|
File -> New
New Document
New View
Window -> New
Same Document
New View
|
|
|
|
|
So, here's the issue:
#ifndef ___GLOBALS_H___
#define ___GLOBALS_H___
enum AspectRatio {
Aspect4to3,
Aspect5to3,
Aspect5to4,
AspectOther
};
struct GState
{
bool isDebugMode;
AspectRatio aspectRatio;
unsigned int canary;
};
extern struct SState gState;
#endif
and for the declaration:
#include"globals.h"
SState gState;
Now, the problem: this is being compiled with VC6SP5 (yes, I know, there's nothing I can do for the time being). I manually checked that all files are being compiled with the same flags. In most files, I include globals.h and everything is kosher. In *some* files, the address of aspectRatio is bumped by 3. I can't figure out what this could possibly be except some weird alignment issue.
Solutions: if I uncomment char a,b,c;, then everything works. If I put unnamed (or named) bitfields in, either unsigned int : 0 or unsigned int:24 (the former promises to align everything that follows on an int), it's still broken.
So, for example, in one file,
printf("isDebugMode = %u, address = %X \naspect ratio = %u, address = %X \n"
"canary=%X, add = %X",
gState.isDebugMode, &(gState.isDebugMode),
gState.aspectRatio, &(gState.aspectRatio),
gState.canary, &(gState.canary));
canary is being set to 0x12344321
results in:
file1.cpp:
isDebugMode = 1, address = 5BAE20
aspectRatio = 2, address = 5BAE21
canary = 12344321, address = 5BAE25
file2.cpp:
isDebugMode = 1, address = 5BAE20
aspectRatio = 876814592, address = 5BAE24
canary = 12, address = 5BAE28
file1.cpp is correct; file2.cpp isn't. The address for aspectRatio is being bumped by 3. Can anyone tell me what the hell is going on?
Thanks,
earl
PS: struct member alignment is set to 8 bytes in the compilation flags.
-- modified at 20:27 Monday 3rd July, 2006
|
|
|
|
|
Put a #pragma pack instruction around the struct definition. The compiler option just sets the default packing, some other buggy header may be changing the packing and not resetting it.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
VB > soccer
|
|
|
|
|
While trying to add a new dialog (for login), after I build the dialog resource and compile the new class, I get errors saying that the IDD_DIALOG1 can't be found, even though it is in the .h file. This is where the error message points back to (the .h file). Anyone know why this is reacting the way it is. This is the first version of Visual C++ 6.0.
Thanks.
John P.
|
|
|
|
|
Check to make sure that the IDD_DIALOG1 has a unique definition in your resource.h file.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
The IDD_DIALOG1 is unique. Also the ID_EMPID and ID_EMPPIN, for the two text iput boxes also generate errors. This .EXE file was created by a third party and supposedly we can add new items to this workspace/project. Is there any kind of control that the original maker can add in Visual C++ that inhibits or prevents new items from being added?
Thanks for your input.
John P.
|
|
|
|
|
So, if I understand you correctly, you have the source code for a third party application and are adding a new resource (and corresponding classes) to it?
That being the case, then no, there is nothing they could do to make it so you cannot add a new resource.
What error are you getting exactly?
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
For the IDD_DIALOG1, the compiler returns:
error C2065: undeclared identifier
error C2057: expected constant expression
Even though the IDD_DIALOG1 is in the .h file as:
//{{AFX_DATA (CloginDialog)
enum { IDD_DIALOG1 };
CString m_empIDnum;
CString m_empPIN;
//}}AFX_DATA
I also get errors saying that the two CString variables above are "undefined"
This just doesn't make sense since Visual C++ made them part of the code.
Thanks, Zac.
John P.
|
|
|
|
|
Typically, the ClassWizard will inject the following when creating a new class:
enum { IDD = IDD_DIALOG1 };
CString m_empIDnum;
CString m_empPIN;
Is your class name lowercased like that? Usually you see "CLoginDialog". Chances are it is a typo along those lines somewhere.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
have you add the #include "resource.h" in you application?
in fact, these resource are defined in resource.h.
|
|
|
|
|
To all three of you who suggested that I add the resource.h file ---- THANKS.
What can I say but DUH!! Sometimes it's too obvious??
Thanks again!
John P.
|
|
|
|
|
#include "resource.h"
hello
|
|
|
|
|
#include "resource.h" before the class declaration.
MANISH RASTOGI
|
|
|
|
|
hi all,
can any one provide any info about searching for files using regular expressions.
something like [a-z]+[0-9].[a-z][0-9].
please provide links to any white papers or articles.
thanks,
sombhotla.
|
|
|
|
|
Hello,
How can I use com written in vc6 from c++.net managed code?
Thanks,
|
|
|
|
|
Hi!
I have a function which returning me LPCST i.e char*.
I want this value to be stored in array of 255 chars decleared as :
char Arr[255];
how can i do this ??
Thx in advance
|
|
|
|
|
Returning a char array this way is tricky. Either you have to allocate the memory inside the function and free it outside (which is very ugly), or you can pass the pointer as a parameter of the function and manipulate its content. Anyway, it is much better to use the std::string (from the Standard Template Library) for which you don't need to care about memory usage.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
|
If you can modify the function (that is, you control it), you can make the return value part of the function arguments:
void getMyString(char[255]& retString)
{
memset(retString, 0, 255);
strncpy(retString, srcString, 254);
}
If you don't have access, or are not allowed to change the interface, here are some alternatives:
char buffer[255] = {0};
strncpy(buffer, myFunction(), 254);
std::string myString = myFunction();
Note that both of those can be sketchy if the returning function is allocating memory on the heap and expecting you to handle cleanup (very poor design, but not too uncommon, sadly). Just keep that in mind when dealing with this kind of thing.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac Howland wrote: void getMyString(char[255]& retString)
That won't work.
|
|
|
|
|