Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7944133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:28:04+00:00 2026-06-04T00:28:04+00:00

Hello im trying to update google admboads to V6 but im having some trouble

  • 0

Hello im trying to update google admboads to V6 but im having some trouble to bind the following and expose it to managed world

I have the following struct

typedef struct GADAdSize {
  CGSize size;
  NSUInteger flags;
} GADAdSize;

and I did this on monotouch side

[StructLayout(LayoutKind.Sequential)]
public struct GADAdSize
{
    public SizeF size;
    public uint flags;
}

I have the following code

extern GADAdSize const kGADAdSizeBanner;
extern GADAdSize const kGADAdSizeMediumRectangle;

I can’t bind it using [Field] Attribute since docs specify that Field attribute can only be used for

  • NSString references
  • NSArray references
  • 32-bit ints (System.Int32)
  • 32-bit floats (System.Single)
  • 64-bit floats (System.Double)

So I tried the following 2 ways i could think of

[DllImport ("__Internal")]
    extern static IntPtr kGADAdSizeMediumRectangle ();

public static GADAdSize MediumRectangle 
{
    get 
    {
        object obj = Marshal.PtrToStructure(kGADAdSizeMediumRectangle(), typeof(GADAdSize));
        return (GADAdSize) obj;
    }
}

and

public static GADAdSize Banner 
{
    get 
    {
        var handle = Dlfcn.dlopen ("libGoogleAdMobAds", 0);
        IntPtr ptr = Dlfcn.GetIntPtr(handle, "kGADAdSizeBanner");   
        Dlfcn.dlclose (handle);     
        object obj = Marshal.PtrToStructure(ptr, typeof(GADAdSize));
        return (GADAdSize) obj;
    }
}

And on both ways it crashes

Using the DLLImport I get a nullargument exception when calling Marshal.PtrToStructure() and the second one rises an DLLNotFoundException System.ArgumentNullException

Thanks in advance for any help

Alex


Edit:

Sorry @Poupou my bad, it throws a System.ArgumentNullException the handle value its 0 also the ptr value its 0

and the stacktrace is:

System.ArgumentNullException: Argument cannot be null.
Parameter name: src
  at (wrapper managed-to-native) System.Runtime.InteropServices.Marshal:PtrToStructure (intptr,System.Type)
  at AlexTouch.GoogleAdMobAds.GADAdSizeConstants.get_Banner () [0x00000] in <filename unknown>:0
  at MobclixText.MobclixTextViewController.ViewDidLoad () [0x00006] in /Users/Alex/Projects/MobclixText/MobclixText/MobclixTextViewController.cs:33
  at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend (intptr,intptr)
  at MonoTouch.UIKit.UIWindow.MakeKeyAndVisible () [0x00010] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIWindow.g.cs:98
  at MobclixText.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x00031] in /Users/Alex/Projects/MobclixText/MobclixText/AppDelegate.cs:44
  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
  at MobclixText.Application.Main (System.String[] args) [0x00000] in /Users/Alex/Projects/MobclixText/MobclixText/Main.cs:17

I guess this is due to handle being 0.

About your comment

Using dlsym with one of the special flags (man dlsym) might help.

Could you provide me an example on how to use it please =) ??

Alex


Edit 2:

Hello @Poupou and thanks for your answer, but with

IntPtr RTLD_MAIN_ONLY = (IntPtr) (-5);
IntPtr ptr = Dlfcn.GetIntPtr (RTLD_MAIN_ONLY, "kGADAdSizeBanner");

I still get ptr equals to 0 any other idea??

Alex


Edit 3:

Ok, im trying the following now

IntPtr RTLD_MAIN_ONLY = Dlfcn.dlopen (null, 0);
IntPtr ptr = Dlfcn.dlsym (RTLD_MAIN_ONLY, "kGADAdSizeBanner");              
Console.WriteLine("RTLD_MAIN_ONLY: " + RTLD_MAIN_ONLY);
Console.WriteLine("ptr: " + ptr);

Dlfcn.dlopen (null, 0); as its done here now I’m getting a handle value -2 but I guess native linker it’s removing the symbol now, how can I prevent this from happening??

Thanks a lot for your time @Poupou

Alex

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:28:06+00:00Added an answer on June 4, 2026 at 12:28 am

    So I found a way to get the values. The first part is to convince the linker to export the symbol (without hiding any existing ones). That can be done by creating an alias (which by default is global) of the (local) symbols. E.g.

    -gcc_flags="-Xlinker -alias -Xlinker _kGADAdSizeBanner -Xlinker _MTAdSizeBanner"
    

    Afterward the code:

    IntPtr RTLD_MAIN_ONLY = Dlfcn.dlopen (null, 0);
    IntPtr ptr = Dlfcn.dlsym (RTLD_MAIN_ONLY, "MTAdSizeBanner");
    object obj2 = Marshal.PtrToStructure(ptr, typeof(GADAdSize));
    

    will give you an instance of GADAdSize with a value of 320×50.

    You’ll need to re-export every symbol you need (yuck) but that should be possible to include this in the [LinkWith] attribute (iirc) so it won’t be a requirement for end users.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I'm trying to install maven plugin with eclipse and I have a following
Hello I am trying to update the textview at every certain time, but it
Hello I'm trying something .. I was reading Jquery traversing documentations some forums, this
I'm trying to update some existing code that normally runs a Perl script which
hello fellow java developers. I'm having a very strange issue. I'm trying to read
I created a sample hello world application using Flash Builder 4.5.1 (with the update
Hello i'm trying to create a page to update a row in my database
I'm trying to use the latest Google NaCl SDK. Following the instructions at https://developers.google.com/native-client/pepper18/devguide/tutorial
Having trouble merging a branch with the trunk. The branch I am trying to
I am trying to update an atomic count counter with Python Boto 2.3.0, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.