Debugging win32 dll

S

Steve Long

Hello,
I have developed a small win32 dll in C++ and exported a function from it
using a DEF file. I'm using the DllImport attribute to import this function.
I've tested the function in a vsc++ console app, (just the code not as a
dll), and it works as expected. However, I'm having some trouble using it
from my C# app. Is there a way I can step into the imported function from
C#?

I appreciate any help I can get on this one.
Thanks
Steve
 
N

Nicholas Paldino [.NET/C# MVP]

Steve,

Are you sure it is not in your delcaration in C# that could be the
issue? What is the declaration in C++ and what is the declaration in C#?

Also, you can debug it by adding the project to the solution I believe,
and making sure the debug version of the dll is the one that is bound to by
..NET.

Hope this helps.
 
S

Steve Long

Hi Nicholas. I'm getting into the function in the dll I know because it is
creating a log file. It's just not getting any further than that and I can't
figure out why because it's not actually logging anything, just creating the
file.

I'll see if I can step in the way you are suggesting.

Thanks
Steve

Nicholas Paldino said:
Steve,

Are you sure it is not in your delcaration in C# that could be the
issue? What is the declaration in C++ and what is the declaration in C#?

Also, you can debug it by adding the project to the solution I believe,
and making sure the debug version of the dll is the one that is bound to by
.NET.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Steve Long said:
Hello,
I have developed a small win32 dll in C++ and exported a function from it
using a DEF file. I'm using the DllImport attribute to import this
function.
I've tested the function in a vsc++ console app, (just the code not as a
dll), and it works as expected. However, I'm having some trouble using it
from my C# app. Is there a way I can step into the imported function from
C#?

I appreciate any help I can get on this one.
Thanks
Steve
 
S

Steve Long

Nicholas, I don't know if you're still listening to this thread or not but I
was able to finally get back to this project after being called off for a
bit.
Here's what I found out.
I added the C++ project to my C# project/solution. I changed to [DllImport]
statement to look like this:

[DllImport(@"C:\Projects2003\C++\CCArcSDELib\Debug\CCArcSDELib.dll")]
This reflects the location of the debug compiled dll.

The declaration in my C# project looks like:
public static extern long AddPoint([MarshalAs(UnmanagedType.LPTStr)] string
server,
[MarshalAs(UnmanagedType.LPTStr)] string instance,
[MarshalAs(UnmanagedType.LPTStr)] string database,
[MarshalAs(UnmanagedType.LPTStr)] string user,
[MarshalAs(UnmanagedType.LPTStr)] string pwd,
ESRIPOINT pt,
[MarshalAs(UnmanagedType.LPTStr)] string table,
FIELD_VAL[] vals,
int numFields);

structs:

public struct ESRIPOINT{
public double x;
public double y;
}

public struct FIELD_VAL{
public int field_type;
public string field;
public string fldval;
}


The C++ prototype looks like:
long __stdcall AddPoint(LPCTSTR server, LPCTSTR instance, LPCTSTR database,
LPCTSTR user, LPCTSTR pwd, ESRIPOINT
pnt, LPCTSTR table,
FIELD_VAL fldVals[], int numFields);

structs:

typedef struct{
int field_type;
CHAR* field;
CHAR* value;
} FIELD_VAL;

typedef struct{
double x;
double y;
}ESRIPOINT;

However, the debugger is not stepping into the C++ project still. I'm not
sure how to make that happen. I know, at least some, of the code is being
reached as it's creating a log file that is coded to create in the
implemented function body. But then, things break down and I can't tell why.

Any more help? Should I repost?
Steve

Nicholas Paldino said:
Steve,

Are you sure it is not in your delcaration in C# that could be the
issue? What is the declaration in C++ and what is the declaration in C#?

Also, you can debug it by adding the project to the solution I believe,
and making sure the debug version of the dll is the one that is bound to by
.NET.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Steve Long said:
Hello,
I have developed a small win32 dll in C++ and exported a function from it
using a DEF file. I'm using the DllImport attribute to import this
function.
I've tested the function in a vsc++ console app, (just the code not as a
dll), and it works as expected. However, I'm having some trouble using it
from my C# app. Is there a way I can step into the imported function from
C#?

I appreciate any help I can get on this one.
Thanks
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top