|
(This is a clarification of my prev post - I dont mean to spam but somehow i cannot modify my old post - sorry!)
I have no trouble passing __delegate ptrs to native C functions in DLLs,
however when attempting to pass the __delegate ptr to a native C++ function
in a DLL I get the following runtime exception: An unhandled exception of
type 'System.EntryPointNotFoundException'.
This is confusing b/c if the entry point was not found, I would think I'd
get an unresolved symbol error during linking. Furthermore, I can
successfully pass void, int *, and function pointers, etc to C++ DLL
functions, but this error persists when attempting to pass a __delegate
pointer, which is used for callbacks to managed C++ functions.
Here is the relevant code snippet - the DLL code simply contains stubs of
the functions called here:
using namespace System;
using namespace System::Runtime::InteropServices;
__delegate void testCB();
[DllImport("unmdll.dll")]
void fnunmdll_2(testCB *UpdateProgMeter);
int fnunmdll_0(void);
void fnunmdll_1(int);
__gc class C1
{
public:
static void handleCB()
{
return;
}
};
int _tmain()
{
int k = 9;
//always works (as both C/C++)
fnunmdll_0();
//always works (as both C/C++)
fnunmdll_1(k);
testCB *pCB = new testCB(0, &C1::handleCB);
//if this is a C++ function expecting a function pointer, the
aforementioned error occurs. If this is an extern C function, all is ok!
fnunmdll_2(pCB);
return 0;
}
As crazy as it sounds, I'm beginning to think this is not possible to do this
with native C++ functions.
Thanks in advance, George
|
|
|
|
|
answer: use a .def file in the dll so mangled names are not used. pinvoke doesnt like them i guess.
|
|
|
|
|
I guess you shound use a pin pointer to prevent your delegate from being moving around, and cast the delegate to its native type, void () in this case.
Pin pointer convertion is the only way to cast gc types to native types.
http://blog.joycode.com/jiangsheng
http://blog.csdn.net/jiangsheng
Command what is yours
Conquer what is not
---Kane
|
|
|
|
|
I have no trouble using __delegate classes to pass callbacks to native exported C functions, however if I am make the call to an exported function written in C++ and NOT in C, then I get unresolved symbol errors. It’s quite frustrating b/c it seems like it’s just a syntactical thing that shouldn’t be so difficult.
If anyone could point me to a sample where this works, it would be much appreciated! (I don't mind aving to use dllimport to accomplish this).
Thanks in advance, George
//////////Example/////////////
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
using namespace System::Runtime::InteropServices;
typedef long (_stdcall *CallbackProc) (int lfunctionVal, int lVal, const char *msg);
__delegate long testCB(int, int, const char *);
[DllImport("unmdll.dll")]
extern void __stdcall fnunmdll2(testCB *UpdateProgMeter, int x);
__gc class C1
{
public:
static long handleCB(int x, int y, const char * z)
{
return 0;
}
};
int _tmain()
{
testCB *tmp1 = new testCB(0, &C1::handleCB);
fnunmdll2(tmp1, 0); //if written i C, i am ok. If in C++ it is unresolved! Why?
return 0;
}
|
|
|
|
|
i hav some code in vc# . but i need this in MC++. NET
How to Do this ?
main()
{
string dom = Environment.UserDomainName;
System.DirectoryServices.DirectoryEntry entry = new System.DirectoryServices.DirectoryEntry("LDAP://" + dom);
System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry);
mySearcher.Filter = ("(objectClass=computer)");
mySearcher.Filter = ("(objectClass=computer)");
foreach(System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
{
try
{
System.DirectoryServices.DirectoryEntry de = resEnt.GetDirectoryEntry();
Console.WriteLine("User Name : " + de.Properties["SAMAccountName"].Value.ToString());
}
catch(Exception e)
{
}
}
Console.ReadLine();
}
}
i need to convert this code to MC++ .
How can i do thisd to in MC++ Specially foreach() part.
pls i need experts help.........
i am waiting some reply.....
Sukanta banik
|
|
|
|
|
Replace the . with :: to scope methods in namespaces.
FindAll returns a SearchResultCollection. It has a Count property, so you can do a normal loop and address each item in the collection by index.
SearchResultCollection src = mySearcher.FindAll();
for(int i =0; i < src.Length; ++i)
{
System::DirectoryServices::DirectoryEntry de = src[i].GetDirectoryEntry();
}
This is not tested, but you get the idea.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I am making a project under visual .NET studio on 2003 with c++. I have libraries developped in Visual C++. And my problem it is for inclures as libraries in my project. I have file corresponding .lib in libraries.
The error is: LNK2001: 1 to unresolver external
thanks for the information
|
|
|
|
|
This error means you provided a header file for an external method, but not a lib to link to.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Yup, make sure you've added the referenced project to to referring project's dependencies.
|
|
|
|
|
I am trying to save files into a specific folder. However if the folder does not exist i get an error saving the file. Ok so i want to create the folder if it does not exist. I thought i would try File::Create("myfoldername") but it just creates a generic file. I looked up Folder::Create() but i am unsure how to use it, the examples only show VB,VBScript. Any suggestions?
|
|
|
|
|
It just takes a path, doesn't it ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
It's not working that way for me, although i thought it would.
|
|
|
|
|
Apparently, you need Directory::CreateDirectory.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi all,
I've got an managed c++ application that needs to display certain information in a graphical display. I've already got things started for the prototype using some basic images. I'm wondering if I could (fairly easily) create some more dynamic images using flash or some other. Basically I'm trying to gauge how easily, if at all possibe, it would be to have some flash images displaying real time data that my managed c++ code creates.
If anyone can point me in the right direction that is all I require.
Thanks in advance.
|
|
|
|
|
The way to display flash is to host IE as a control in a window. Personally, I think it's a bad idea, for starters, if your flash contains UI elements, I'm not sure how their events can be passed from your IE window into your code.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I have a MDI app and I want to have a image in the client area. I can't use the Picture control because it hides the MDIchild Forms. I tried to send the Picture control to the back after I display the child form, but it disappears. Even when I use just the image background the image dose not display.
Can anyone help me with this? Thanks.....
|
|
|
|
|
________________
/|__________ /|
/ / / / |
/ / Form / / /
/ / Control /__ / /
/ / /
/ /_________/
/ /MDI Child
/ / Forms
/ /__________
/_______________/ /
| MDI Container | /
|_______________|/
As you can see from ascii picture MDI Container creates any control above any MDI Child forms.
I Have overriden Pant event, but it seems that MDI Background color paints on top of overriden event.
I Know it was posible with VB6. Maybe you have found a bug in framework.
|
|
|
|
|
I have a MDI. I created four Forms that I use as child Forms (not Forms
*form = new Forms() and then init the MDIParent property).
I'm haviing trouble trying to find out how I can access public variables of
the MDI parent from the child Forms.
The MainForm has the include .h files of all my Forms I am using, but when I
include the MainForm.h in the child Forms I get compiler errors in:
MainForm: ChildForm1 is undeclared....
ChildForm: missing ';' before '*' (referring to MainForm *parent)
How do I properly access my public variable in the parent? Thanks!...
|
|
|
|
|
|
Thanks for the link to those disscusions. I was able to solve my problem. This method allows me to use the MFC document view method. I use a __gc class as my ducument interface between my Main and child Forms. Cool!...
|
|
|
|
|
I can't seem to find any examples (or reference) for displaying images in a Column of a data grid without some sort of webcontrol.
This is for a simple non databased windows app..
Can someone point me in the right direction?
|
|
|
|
|
I seem to recall there are some examples for how to insert your own controls in a datagrid, but most online examples seem to focus on a combobox. Surely it would be simplicity itself to change one of those examples to put in a picture box ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I agree.. however I can only seem to dig up combobox examples that use a Web form instead of a standard windows form. :/
Got any specific links?
Thanks in advance!
|
|
|
|
|
|
from what i get this is a question where more programmers need help, so :
i'm a novice programmer on Visual studio.net c++ and i need to connect it to mysql 4.1.17, it can be done with myodbc, bytefx or oledb, or another one that results, to make the normal operations (insert, select, delete, update ).
please help fast, it's really importante, and a sample application would be great, send it to horus.cv@gmail.com, but the code and the explanation is also good.please help,
thanks
|
|
|
|