Click here to Skip to main content
15,922,407 members
Home / Discussions / C#
   

C#

 
GeneralRe: Delete in Textbox Pin
Yulianto.7-Mar-05 19:47
Yulianto.7-Mar-05 19:47 
GeneralRe: Delete in Textbox Pin
chettu7-Mar-05 20:28
chettu7-Mar-05 20:28 
GeneralRe: Delete in Textbox Pin
Yulianto.7-Mar-05 21:00
Yulianto.7-Mar-05 21:00 
GeneralSystem.Net.WebException: The underlying connection was closed Pin
Liu Shuai7-Mar-05 10:42
Liu Shuai7-Mar-05 10:42 
GeneralTray Application Pin
kaka227-Mar-05 10:11
kaka227-Mar-05 10:11 
GeneralRe: Tray Application Pin
Liu Shuai7-Mar-05 10:31
Liu Shuai7-Mar-05 10:31 
GeneralRe: Tray Application Pin
bneacetp7-Mar-05 17:07
bneacetp7-Mar-05 17:07 
GeneralUsing Marshal Pin
gmhanna7-Mar-05 7:51
gmhanna7-Mar-05 7:51 
Hi,

I'm trying to call a program in a .dll file that is built with C. The .dll program takes a pointer to a structure and then will return that structure with additional information filled in. The .dll program will also return a BOOL if the function was successful or not.

I have no problem calling the function, I'm having a problem building a structure that I can pass with a pointer.

From what I have been reading, I should be able to allocate a chunk of memory for the structure to hold, copy the existing data into the memory area and pass a pointer.

Attached below is my code that I am having a difficult time getting to compile. It starts with line number 265 with unsafe.
<br />
unsafe<br />
{<br />
<br />
IntPtr pCreditCardStruct = Marshal.AllocHGlobal(sizeof(CreditCardStruct));<br />
Marshal.StructureToPtr(CreditCardStruct, pCreditCardStruct, false);<br />
Marshal.Copy(CreditCardStruct, 0, pCreditCardStruct, sizeof(CreditCardStruct));<br />
}<br />
<br />
_ProcAuthorizationWeb(pCreditCardStruct);<br />


The structure looks like this:
<br />
[StructLayout (LayoutKind.Sequential)]<br />
public class CreditCardStruct<br />
{<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 15)] public string strTransType;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 30)] public string strMerchant;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 11)] public string strInvoiceNumber;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 24)] public string strCardNumber;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4) ] public string strCVV2;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 5) ] public string strExpDate;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 35)] public string strCardHolderName;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 25)] public string strStreetAddress;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)] public string strZipCode;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 9) ] public string strTransAmt;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 7) ] public string strAuthCode;<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)] public string strResponse;<br />
[MarshalAs(UnmanagedType.Bool)] public bool bCardPresent;<br />
[MarshalAs(UnmanagedType.Bool)] public bool bCustomerPresent;<br />
[MarshalAs(UnmanagedType.Bool)] public bool bDeferred;<br />
}<br />


The error messages I'm getting are:

q:\mcp\authorization.aspx.cs(268,61): error CS0208: Cannot take the address or size of a variable of a managed type ('MCP.CreditCardStruct')
q:\mcp\authorization.aspx.cs(270,66): error CS0208: Cannot take the address or size of a variable of a managed type ('MCP.CreditCardStruct')
q:\mcp\authorization.aspx.cs(270,6): error CS1502: The best overloaded method match for 'System.Runtime.InteropServices.Marshal.Copy(int[], int, System.IntPtr, int)' has some invalid arguments
q:\mcp\authorization.aspx.cs(270,19): error CS1503: Argument '1': cannot convert from 'MCP.CreditCardStruct' to 'int[]'
q:\mcp\authorization.aspx.cs(273,27): error CS0103: The name 'pCreditCardStruct' does not exist in the class or namespace 'MCP.Authorization'

It appears that I can not use sizeof for the structure since its in "SAFE" code and I have the wrong format for the Marshal.Copy but from what I'm reading in the documentation it should be right.

Any ideas what I'm doing wrong and what is the best way to do this?

Thank you very much,

Glenn
GeneralRe: Using Marshal Pin
Mathew Hall7-Mar-05 21:41
Mathew Hall7-Mar-05 21:41 
Generalcallback to c++ Pin
reuvenkupfer7-Mar-05 7:41
reuvenkupfer7-Mar-05 7:41 
GeneralAdding worksheets to Excelfiles Pin
zaubara7-Mar-05 6:50
zaubara7-Mar-05 6:50 
Questionhow to check if workstation is locked/logged off Pin
Rene_Steen7-Mar-05 6:15
Rene_Steen7-Mar-05 6:15 
GeneralPrinting HTML Files programmatically Pin
BrettMostert7-Mar-05 6:05
BrettMostert7-Mar-05 6:05 
GeneralExplorer Band Objects and the DOM Pin
Dustin Lyday7-Mar-05 5:43
Dustin Lyday7-Mar-05 5:43 
GeneralLooping through listbox selections in Windows Pin
scotlandc7-Mar-05 5:36
scotlandc7-Mar-05 5:36 
GeneralC# CAS question Pin
elapid7-Mar-05 4:43
elapid7-Mar-05 4:43 
GeneralRe: C# CAS question Pin
Dave Kreskowiak7-Mar-05 9:47
mveDave Kreskowiak7-Mar-05 9:47 
GeneralEmail Client Application Pin
kaka227-Mar-05 4:12
kaka227-Mar-05 4:12 
GeneralRe: Email Client Application Pin
Judah Gabriel Himango7-Mar-05 6:04
sponsorJudah Gabriel Himango7-Mar-05 6:04 
GeneralRe: Email Client Application Pin
kaka227-Mar-05 9:37
kaka227-Mar-05 9:37 
GeneralWindows Forms personalization Pin
innocent737-Mar-05 3:26
innocent737-Mar-05 3:26 
GeneralCustom Controls Pin
chettu7-Mar-05 2:24
chettu7-Mar-05 2:24 
QuestionHow to get the number of items in enum ? Pin
Andres Coder7-Mar-05 2:03
Andres Coder7-Mar-05 2:03 
AnswerRe: How to get the number of items in enum ? Pin
turbochimp7-Mar-05 3:05
turbochimp7-Mar-05 3:05 
AnswerRe: How to get the number of items in enum ? Pin
mav.northwind7-Mar-05 3:17
mav.northwind7-Mar-05 3:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.