|
You want a masked edit control?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
can someone please help me with a problem i have with dll files.
i can call functions from the dll files i make but i was wondering how i could use the returned variable from 1 function in another function inside my dll file.
if anyone can help me i would appreciate it a lot.
the more you learn the less you know, no one is truely a master. cause the more you seek to be the master the less of a master you become.
|
|
|
|
|
Swatgod wrote:
i can call functions from the dll files...
Are they called from some other DLL or EXE, or are they called from within the DLL itself?
Swatgod wrote:
...i was wondering how i could use the returned variable from 1 function in another function inside my dll file.
Does the function return a value? If so, treat it just like any other function that returns a value. The fact that it resides in a DLL is irrelevant.
In Prog.exe:
int x = SomeFunc(); In DLL:
int SomeFunc( void )
{
return 123;
}
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
well the functions are called from a dll i made and the way that i have seen done, wont let me do it like that, her ei show a small sample of how my functions are called in the exe from my dll file.
ProcAdd=(MYPROC)GetProcAddress(hinstLib,"firstlast");
if(fRunTimeLinkSuccess = (ProcAdd != NULL))
(ProcAdd)("firstlast");
the more you learn the less you know, no one is truely a master. cause the more you seek to be the master the less of a master you become.
|
|
|
|
|
Are you getting compiler or runtime errors? Are any assertions firing, or exceptions thrown? Does hinstLib have a non-NULL value? Do you know the name of the exported function to be "firstlast?" What does the declaration of ProcAdd look like?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
here is the code of the main application. the first 2 functiosn that i have seen went through fine but when it loads the 3rd which is the one that needs input from other 2, it crashes.
#include <stdio.h>
#include <windows.h>
typedef void (*MYPROC)(LPTSTR);
void main()
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
hinstLib = LoadLibrary("name");
if(hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "firstn");
if(fRunTimeLinkSuccess = (ProcAdd != NULL))
(ProcAdd)("firstn");
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "lastn");
if(fRunTimeLinkSuccess = (ProcAdd != NULL))
(ProcAdd)("lastn");
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "firstlast");
if(fRunTimeLinkSuccess = (ProcAdd != NULL))
(ProcAdd)("firstlast");
fFreeResult = FreeLibrary(hinstLib);
}
if(! fRunTimeLinkSuccess)
printf("--loading of main dll failed--");
}
the more you learn the less you know, no one is truely a master. cause the more you seek to be the master the less of a master you become.
|
|
|
|
|
What is the signature of the first() , last() , and firstlast() functions within the DLL?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
the main source of the dll file is:
#include "stdafx.h"
#include <stdio.h>
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
extern "C" __declspec(dllexport) firstn();
extern "C" __declspec(dllexport) lastn();
extern "C" __declspec(dllexport) firstlast(char first, char last);
extern "C" __declspec(dllexport) firstn()
{
char first[10];
printf(" What is your first name: ");
scanf(" %s", first);
return (char)first;
}
extern "C" __declspec(dllexport) lastn()
{
char last[10];
printf(" What is your last name: ");
scanf(" %s", last);
return (char)last;
}
extern "C" __declspec(dllexport) firstlast(char first, char last)
{
printf(" your first and last name is %s %s.", first, last);
return 0;
}
once again thank you for your help.
the more you learn the less you know, no one is truely a master. cause the more you seek to be the master the less of a master you become.
|
|
|
|
|
Swatgod wrote:
extern "C" __declspec(dllexport) firstn()
{
char first[10];
printf(" What is your first name: ");
scanf(" %s", first);
return (char)first;
}
The first variable goes away once firstn() loses scope. Therefore, the return statement, in its current form, is useless. Since no return type was specified, int is assumed. This conflicts with first being cast to a char .
The same holds true for the lastn() function.
Swatgod wrote:
extern "C" __declspec(dllexport) firstlast(char first, char last)
{
printf(" your first and last name is %s %s.", first, last);
return 0;
}
The first and last variables are of type char , but you are treating them as null-terminated strings in the call to printf() . This is a sure-fire recipe for stack corruption.
Also, the prototypes near the top are not necessary.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
in the firstlast function i made it so it used a char array for both and made the other functions with return type char as before it was causing trouble with it going directly to int.
but the program is still crashing between the end of the 2nd function and start of the 3rd but now it actually prints soemthign from the 3rd function.
the more you learn the less you know, no one is truely a master. cause the more you seek to be the master the less of a master you become.
|
|
|
|
|
Whatever result you are seeing that happens to look correct is pure coincidence. The correct way to do this is:
extern "C" __declspec(dllexport) void firstn( LPSTR lpFirst )
{
printf("What is your first name: ");
scanf("%s", lpFirst);
}
extern "C" __declspec(dllexport) void firstlast( LPCSTR lpFirst, LPCSTR lpLast)
{
printf("Your first and last name is %s %s.", lpFirst, lpLast);
}
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
if someone who is very good with dll files could help me i would appreciate it alot.
i do not think it was clear what i was asking before so i guess i should restate it.
i will use an example(very small and simple example) to explain what i need help with. say i wanted the program to gather a person's first and last name using 2 functions that return the variables that the first and last name are stored in and than another function uses those variables to output the person's first and last name to the screen.
plz if someone could help me figure this out i would appreciate it alot(sorry for the example, only easy thing i could come up with).
the more you learn the less you know, no one is truely a master. cause the more you seek to be the master the less of a master you become.
|
|
|
|
|
I have written a C++ project that runs fine. Now I would like to give the person an option to print it. How to I incorporate my C++ code into the MFC environment so when it runs a printout could be made. Right now I am running the program and can only use the exe file.
|
|
|
|
|
maybe, if you manipulate doc files, you can use ShellExecute() with the "print" option...
TOXCCT >>> GEII power
|
|
|
|
|
I am sorry. I am not yet up to manipulating docs. I thought I could go into the MFC exe. and create it through that process. I was also thinking that after I compiled and ran my program I could go and create the print option with MFC. Are there any good books that I can read for this purpose.
|
|
|
|
|
"Now I would like to give the person an option to print it."
Print it , what is "it" . C++ Source code ?
"How to I incorporate my C++ code into the MFC environment so when it runs a printout could be made"
again print out of what .
|
|
|
|
|
After I run my code I am left with an exe file. When I run the program I am not able to print it. I would like to be able to run the program and print it out.
|
|
|
|
|
BRIMID wrote:
I would like to be able to run the program and print it out.
the program ??? hum, i think it's not clear in your mind about what a binary/compiled program looks like...
TOXCCT >>> GEII power
|
|
|
|
|
BRIMID wrote:
I have written a C++ project that runs fine. Now I would like to give the person an option to print it.
Print what? By "C++ project" do you mean you want to print the source code that your C++ project is comprised of? Otherwise, "printing my program" makes no sense.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hi,
I've programmed my win32 app and it works correctly, but, suddenly, it doesn't works (yes, I know it's incredible, but true )
The trouble is in CreateThread, I have this:
hThread = CreateThread(NULL, 0, RunTask, NULL, 0, &dwThreadId);
if (hThread == NULL) return FALSE;
and the function:
DWORD WINAPI RunTask (LPVOID)
I execute the app, step by step, and hThread takes a correct value and GetLastError returns me 0 (there isn't any error)
So, why don't execute the function??? I don't understand it because some days ago the program works correctly and I've not added or removed any instruction
Has someone any idea about this mystery?
Thanks in advance
|
|
|
|
|
DWORD WINAPI RunTask (LPVOID)
probably you should write
DWORD WINAPI RunTask (LPVOID pParam)
otherwise I have no idea or you aren't coherent
gabby
|
|
|
|
|
Is this a RAW Win32 Application?
If oyu use the C-Run Time Library, you might want to read about _beginthreadex and possibly use it instead. The wealth of warnings against using CreateThread is quite fascinating. This COULD possibly be your problem.
|
|
|
|
|
Could someone explain "traits" so that an idiot (myself) can understand it. I have 3 STL books and I still dont get it...
thanks-
|
|
|
|
|
I'll try to explain what traits are with a simple example. Suppose you're writing a template function for advancing an iterator n positions:
template<typename Iterator>
Iterator advance(Iterator it,size_t n)
{
for(size_t i=0;i<n;++i){
++it;
}
return it;
} So far so good. After writing this, you promptly realize that advance can be implemented in a more efficient maner when the iterator is a pointer. You consult your C++ book about partial template specialization and write the following:
template<typename T>
Iterator advance(T* it,size_t n)
{
return it+n;
} So yo have the default implementation for any type of iterator and a fast implementation for pointers (of course, the fast solution is not applicable to every iterator type, since forward iterators can only be advanced one step at a time.) This is OK, but it is not perfect: some iterators, which are not pointers, could benefit of the fast implementation. Specializing advance for every random-access iterator you know of is not practical, since the user can provide her own iterators, and you want to remain as generic as possicle. What you'd really want to write is:
template<typename Iterator>
Iterator advance(Iterator it,size_t n)
{
if(Iterator is random-access){
return it+n;
}
else{
for(size_t i=0;i<n;++i){
++it;
}
return it;
}
} This pseudocode cannot be easily be turned into real code. How do you express the "Iterator is random-access" constraint? A first shot at this is the following: suppose the iterators you're passed have a nested typedef whose only purpose is to tell you wether they are randon-access or not:
struct random_access_category{};
struct default_access_category{};
template<typename Iterator>
Iterator advance(Iterator it,size_t n)
{
return advance_helper<typename Iterator::category>(it,n);
}
template<typename IteratorCategory,typename Iterator>
Iterator advance_helper(Iterator it,size_t n)
{
for(size_t i=0;i<n;++i){
++it;
}
return it;
}
template<typename Iterator>
Iterator advance_helper<randon_access_category>(Iterator it,size_t n)
{
return it+n;
} So, given an Iterator , its nested typedef Iterator::category can be used to dispatch to the most appropriate implementation of advance . But:- An iterator is not guaranteed to have such a category typedef, no matter how bad you need it.
- Pointers cannot have a nested typedef
Here's where traits enter. Instead of requiring that an iterator type provides information about itself, we obtain such information from a separate class:
struct random_access_category{};
struct default_access_category{};
template <typename Iterator>
struct iterator_traits
{
typedef default_access_category category;
};
template <typename T>
struct iterator_traits<T*>
{
typedef random_access_category category;
};
Iterator advance(Iterator it,size_t n)
{
return advance_helper<typename iterator_traits<Iterator>::category>(it,n);
}
This traits technique allows us to describe built-in types, as I've shiwn before, and also types written by someone else, without touching her source code:
#include "FastIteratorLib.h"
template<typename T>
struct iterator_traits<fast_iterator_lib::fast_iterator<T> >
{
typedef random_access_category category;
} I hope you've gotten the idea. Our advance is now maximmaly efficient and can cope with built-in types and types from external libraries.
Well, this is more or less what traits are: class templates full of nested typedefs whose purpose is to desribe the properties of an external type, so that generic code can take advantage of this extra information.
Did this help?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Joaquin,
Thanks for your answer.It was very helpful- I'm starting to get the picture. I guess haven't written enough STL routines to "think that way" - thanks again
|
|
|
|
|